From a049ee8887af38f416fa9d3d383e2d40d386fd83 Mon Sep 17 00:00:00 2001 From: mawkone Date: Tue, 2 Jun 2026 14:12:14 -0700 Subject: [PATCH] fix: resolve browser tool syntax errors using robust base64 write-and-run pattern --- vibn-frontend/app/api/mcp/browser.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vibn-frontend/app/api/mcp/browser.ts b/vibn-frontend/app/api/mcp/browser.ts index 381f796..4d6db32 100644 --- a/vibn-frontend/app/api/mcp/browser.ts +++ b/vibn-frontend/app/api/mcp/browser.ts @@ -35,8 +35,11 @@ const { chromium } = require('playwright'); })(); `; - // We need to ensure playwright is installed and the browsers are downloaded. - const setupCmd = `if [ ! -d "node_modules/playwright" ]; then npm install --no-save playwright && npx playwright install chromium; fi && node -e "${script.replace(/"/g, '\\"').replace(/\$/g, "\\$")}"`; + // Encode the script to base64 to bypass any shell quoting/escaping conflicts + const scriptB64 = Buffer.from(script, "utf8").toString("base64"); + const tempFile = `.vibn-console-${projectId}.js`; + + const setupCmd = `echo "${scriptB64}" | base64 -d > ${tempFile} && if [ ! -d "node_modules/playwright" ]; then npm install --no-save playwright && npx playwright install chromium; fi && node ${tempFile} && rm -f ${tempFile}`; try { const res = await execInDevContainer({ @@ -99,7 +102,11 @@ const { chromium } = require('playwright'); })(); `; - const setupCmd = `if [ ! -d "node_modules/playwright" ]; then npm install --no-save playwright && npx playwright install chromium; fi && node -e "${script.replace(/"/g, '\\"').replace(/\$/g, "\\$")}"`; + // Encode the script to base64 to bypass any shell quoting/escaping conflicts + const scriptB64 = Buffer.from(script, "utf8").toString("base64"); + const tempFile = `.vibn-navigate-${projectId}.js`; + + const setupCmd = `echo "${scriptB64}" | base64 -d > ${tempFile} && if [ ! -d "node_modules/playwright" ]; then npm install --no-save playwright && npx playwright install chromium; fi && node ${tempFile} && rm -f ${tempFile}`; try { const res = await execInDevContainer({