Playground scripts
Run Playwright code inside the session's own sandbox, right next to its browser.
A playground script is Playwright code that runs inside the session’s own sandbox, next to its browser, so every browser command is a local call. Watch the live view while it runs.
Run a script
POST/v1/sessions/:id/scripts/run with { code, env?, timeoutMs? }. The session needs a shell. Output streams back as newline-delimited JSON, like streaming exec.
page,contextandbrowserare already connected to the session’s browser.envholds your variables. They are never written to the log.- Top-level
awaitworks, and a value youreturnis printed. - Do not call
browser.close(): it would close the session’s browser.
const client = new Boxline();
const session = await client.sessions.create({ shell: true, keepAlive: true });
const result = await session.runScript(
`
await page.goto(env.START_URL);
const links = await page.$$eval("a", (as) => as.map((a) => a.href));
return { count: links.length, first: links.slice(0, 5) };
`,
{ env: { START_URL: "https://example.com" }, onData: (_stream, text) => process.stdout.write(text) },
);
console.log(result.exitCode);These docs describe a beta API. Endpoints, fields and SDK methods may change before general availability; breaking changes will be listed in the changelog.