fix: resolve browser_navigate template interpolation bug by removing accidental backslash escape
This commit is contained in:
@@ -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 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,7 +99,7 @@ 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({
|
||||
@@ -100,21 +109,31 @@ const { chromium } = require('playwright');
|
||||
});
|
||||
|
||||
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 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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user