From 4ff0163ff85357ab5e0b7f91d28161b0b623a135 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Fri, 13 Nov 2026 19:03:45 +0000 Subject: [PATCH] Use Playwright headless Chromium for MCP E2E submits --- apps/builder/e2e/flows/mcp-preview-submit.ts | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/builder/e2e/flows/mcp-preview-submit.ts b/apps/builder/e2e/flows/mcp-preview-submit.ts index 821a61b591..c8b3f3c9a9 100644 --- a/apps/builder/e2e/flows/mcp-preview-submit.ts +++ b/apps/builder/e2e/flows/mcp-preview-submit.ts @@ -1,4 +1,6 @@ import { spawn } from "node:child_process"; +import { existsSync } from "node:fs"; +import { join } from "node:path"; import { fileURLToPath } from "node:url"; import { chromium } from "@playwright/test"; import type { @@ -17,6 +19,26 @@ const cliTsconfigPath = fileURLToPath( new URL("../../../../packages/cli/tsconfig.local.json", import.meta.url) ); +const getMcpBrowserPath = () => { + const chromiumPath = chromium.executablePath(); + const match = chromiumPath.match(/^(.*)[\\/]chromium-(\d+)[\\/]/); + if (match === null) { + return chromiumPath; + } + const [, cacheDir, revision] = match; + const shellPath = join( + cacheDir, + `chromium_headless_shell-${revision}`, + process.platform === "darwin" + ? "chrome-mac" + : process.platform === "win32" + ? "chrome-win" + : "chrome-linux", + process.platform === "win32" ? "headless_shell.exe" : "headless_shell" + ); + return existsSync(shellPath) ? shellPath : chromiumPath; +}; + /** One JSON payload goes over stdin so base64 files are not limited by argv size. */ export const submitPreviewFormViaMcp = async ({ url, @@ -40,7 +62,7 @@ export const submitPreviewFormViaMcp = async ({ env: { ...process.env, TSX_TSCONFIG_PATH: cliTsconfigPath, - WEBSTUDIO_BROWSER_PATH: chromium.executablePath(), + WEBSTUDIO_BROWSER_PATH: getMcpBrowserPath(), }, } ); @@ -65,7 +87,9 @@ export const submitPreviewFormViaMcp = async ({ } else { reject( new Error( - `MCP Preview submit fixture exited ${code}: ${stderr.slice(-4000)}` + `MCP Preview submit fixture exited ${code}: ${stderr.slice( + -4000 + )}` ) ); }