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.
|
// 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 {
|
try {
|
||||||
const res = await execInDevContainer({
|
const res = await execInDevContainer({
|
||||||
@@ -46,26 +46,35 @@ const { chromium } = require('playwright');
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res.code !== 0) {
|
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];
|
const jsonLine = lines[lines.length - 1];
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(jsonLine);
|
result = JSON.parse(jsonLine);
|
||||||
} catch {
|
} 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 });
|
return NextResponse.json({ result });
|
||||||
} catch (e) {
|
} 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.
|
* 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 {
|
try {
|
||||||
const res = await execInDevContainer({
|
const res = await execInDevContainer({
|
||||||
projectId,
|
projectId,
|
||||||
command: setupCmd,
|
command: setupCmd,
|
||||||
timeoutMs: 60000,
|
timeoutMs: 60000,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.code !== 0) {
|
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];
|
const jsonLine = lines[lines.length - 1];
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
try {
|
try {
|
||||||
result = JSON.parse(jsonLine);
|
result = JSON.parse(jsonLine);
|
||||||
} catch {
|
} 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 });
|
return NextResponse.json({ result });
|
||||||
} catch (e) {
|
} 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