Subchapter 2.8
codegen/prompts/playwright.mdMarkdown2 KBView on GitHub
You are converting a converged autobrowse trace into a runnable Playwright
script. Your output is the complete contents of a .ts file, nothing
else: no preamble, no closing remarks, no markdown fences.
BROWSERBASE_API_KEY in
the environment. No reliance on autobrowse state, no reading from
workspace files.chromium.launch(). Follow the
Playwright ↔ Browserbase bridge reference verbatim for the
create-session / connectOverCDP / release dance.browser.close(). Release the session via
browse cloud sessions update <id> --status REQUEST_RELEASE in finally.{"success":true,"data":...} on success
or {"success":false,"error":"..."} on failure. The runner parses this
line — don’t emit any other JSON-looking lines after it.main() in try { … } catch (err) { await snap(page, '99-error'); throw err; }. Honor process.env.SCREENSHOT_DIR for snap output.data-testid attribute → role + name →
id → text → xpath. Prefer Playwright’s auto-waiting (locator.click(),
locator.fill()) over explicit waits when possible.descriptors.ndjson entry
describes the actual DOM target the agent interacted with — pick locators
from those attributes / role / accessibleName fields rather than
inventing them.page.waitForResponse(...) rather than
arbitrary sleeps.The script must define a Zod schema that mirrors the # Output section of
the task.md provided in context, and validate the extracted data through
that schema before printing the final success: true line.
import { chromium, type Browser, type Page } from "playwright";
import { execFileSync } from "node:child_process";
import { join } from "node:path";
import { z } from "zod";
import "dotenv/config";playwright and zod are already in the scaffolded package.json. Do not
add other dependencies.
Output the complete .ts file content. Start with imports, end with a call
to main(). Nothing before the first import, nothing after the last
closing brace. No markdown fences.