Browser Runtime Quickstart

View as Markdown

Launch a cloud browser, automate it with Playwright, and let BCTRL record the whole run. This recipe uses your own Playwright code over a CDP connection - no hosted agent required.

1import { Bctrl } from "@bctrl/sdk";
2import { chromium } from "playwright";
3
4const bctrl = new Bctrl({ apiKey: process.env.BCTRL_API_KEY! });
5
6// Launch a cloud browser runtime
7const runtime = await bctrl.runtimes.create({ type: "browser", name: "quickstart" });
8const { connectUrl, runId } = await bctrl.runtimes.start(runtime.id);
9
10// Drive it with Playwright over CDP
11const browser = await chromium.connectOverCDP(connectUrl);
12const context = browser.contexts()[0] ?? (await browser.newContext());
13const page = context.pages()[0] ?? (await context.newPage());
14
15try {
16 await page.goto("https://example.com");
17 console.log(await page.title());
18} finally {
19 await browser.close();
20 await bctrl.runtimes.stop(runtime.id);
21}
22
23// Everything was recorded on the run
24const events = await bctrl.runs.events.list(runId);
25console.log(`${events.data.length} events recorded`);

The runtime runs on BCTRL infrastructure. Playwright connects through the run-scoped connectUrl, and BCTRL captures the session as a run - events, live view, recording, and files - with nothing to wire up.

Next