From c29587b24ff7dac78c2d1b04d49e1c5239bd087d Mon Sep 17 00:00:00 2001 From: mawkone Date: Tue, 2 Jun 2026 12:32:06 -0700 Subject: [PATCH] fix: resolve browser_navigate template interpolation bug by removing accidental backslash escape --- vibn-frontend/app/api/mcp/browser.ts | 47 +++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/vibn-frontend/app/api/mcp/browser.ts b/vibn-frontend/app/api/mcp/browser.ts index 2252ff9..381f796 100644 --- a/vibn-frontend/app/api/mcp/browser.ts +++ b/vibn-frontend/app/api/mcp/browser.ts @@ -36,7 +36,7 @@ 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, '\\$')}"`; + 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, "\\$")}"`; try { const res = await execInDevContainer({ @@ -46,26 +46,35 @@ const { chromium } = require('playwright'); }); if (res.code !== 0) { - return NextResponse.json({ error: "Failed to run browser test", details: res.stderr }, { status: 500 }); + return NextResponse.json( + { error: "Failed to run browser test", details: res.stderr }, + { status: 500 }, + ); } - const lines = res.stdout.trim().split('\n'); - const jsonLine = lines[lines.length - 1]; + const lines = res.stdout.trim().split("\n"); + const jsonLine = lines[lines.length - 1]; let result; try { result = JSON.parse(jsonLine); } catch { - result = { ok: false, error: "Could not parse browser output", raw: res.stdout }; + result = { + ok: false, + error: "Could not parse browser output", + raw: res.stdout, + }; } return NextResponse.json({ result }); } catch (e) { - return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 }); + return NextResponse.json( + { error: e instanceof Error ? e.message : String(e) }, + { status: 500 }, + ); } } - /** * Executes a simple Playwright script inside the dev container to extract the page title and status code. */ @@ -90,31 +99,41 @@ 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, '\\\\$')}"`; + 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, "\\$")}"`; try { const res = await execInDevContainer({ projectId, command: setupCmd, - timeoutMs: 60000, + timeoutMs: 60000, }); if (res.code !== 0) { - return NextResponse.json({ error: "Failed to navigate", details: res.stderr }, { status: 500 }); + return NextResponse.json( + { error: "Failed to navigate", details: res.stderr }, + { status: 500 }, + ); } - const lines = res.stdout.trim().split('\n'); - const jsonLine = lines[lines.length - 1]; + const lines = res.stdout.trim().split("\n"); + const jsonLine = lines[lines.length - 1]; let result; try { result = JSON.parse(jsonLine); } catch { - result = { ok: false, error: "Could not parse browser output", raw: res.stdout }; + result = { + ok: false, + error: "Could not parse browser output", + raw: res.stdout, + }; } return NextResponse.json({ result }); } catch (e) { - return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 }); + return NextResponse.json( + { error: e instanceof Error ? e.message : String(e) }, + { status: 500 }, + ); } }