Core conceptsBeta

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, context and browser are already connected to the session’s browser.
  • env holds your variables. They are never written to the log.
  • Top-level await works, and a value you return is printed.
  • Do not call browser.close(): it would close the session’s browser.
TypeScript
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.