Page
Page is the primary interface for browser automation. Created via browser.newPage(), it wraps the shared Bun.WebView and exposes chainable methods that return Promise<this>.
const page = await browser.newPage();Properties
Section titled “Properties”| Property | Type |
|---|---|
readonly [CHAINABLE] |
true |
readonly webview |
WebView |
retryTimeout |
number |
Methods
Section titled “Methods”| Method | Signature |
|---|---|
close |
close(): void |
navigate |
navigate(url: string, opts?: { waitForLoadState?: LoadState; }): Promise<this> |
back |
back(): Promise<this> |
forward |
forward(): Promise<this> |
reload |
reload(): Promise<this> |
click |
click(sel: Selector, opts?: { timeout?: number; }): Promise<this> |
dblClick |
dblClick(sel: Selector, opts?: { timeout?: number; }): Promise<this> |
type |
type(sel: Selector, text: string, opts?: { timeout?: number; }): Promise<this> |
press |
press(key: string, modifiers?: Bun.WebView.Modifier[]): Promise<this> |
scroll |
scroll(dx: number, dy: number): Promise<this> |
scrollTo |
scrollTo(sel: Selector, opts?: { block?: "start" | "center" | "end"; timeout?: number; }): Promise<this> |
resize |
resize(width: number, height: number): Promise<this> |
screenshot |
screenshot(path?: string): Promise<this> |
expect |
expect(sel: Selector, opts?: { timeout?: number; }): Promise<this> |
check |
check(sel: Selector): Promise<this> |
waitForLoadState |
waitForLoadState(state: LoadState, opts?: { timeout?: number; }): Promise<this> |
evaluate<T> |
evaluate<T>(fn: () => T): Promise<T> |
locator |
locator(sel: Selector): Locator |
$ |
$(sel: Selector): Promise<import("./locator.js").ElementHandle | null> |
$$ |
$$(sel: Selector): Promise<import("./locator.js").ElementHandle[]> |
waitForSelector |
waitForSelector(sel: Selector, opts?: { timeout?: number; }): Promise<void> |
waitForURL |
waitForURL(url: string | RegExp, opts?: { timeout?: number; }): Promise<void> |
exists |
exists(sel: Selector): Promise<boolean> |
waitFor |
waitFor(sel: Selector, opts?: { timeout?: number; }): Promise<boolean> |
waitForTimeout |
waitForTimeout(ms: number): Promise<void> |
cdp |
cdp(method: string, params?: Record<string, unknown>): Promise<unknown> |
Navigation
Section titled “Navigation”await page.navigate("https://example.com").back().forward().reload();navigate optionally accepts waitForLoadState to block until a specific load state:
await page.navigate("https://example.com", { waitForLoadState: "networkidle",});waitForURL accepts a URL glob (** spans /, * stays within a segment, ? is one character; anchored to the full URL) or a RegExp:
await page.waitForURL("**/dashboard");await page.waitForURL(/\/users\/\d+/);Interaction
Section titled “Interaction”await page .click("role:button[name='Submit']") .type("label:Email", "user@example.com") .press("Enter") .scroll(0, 500) .scrollTo("role:button[name='Save']") .resize(1920, 1080);Every interaction auto-waits for the element to be visible and enabled, then retries up to 3 times with exponential backoff.
Inspection
Section titled “Inspection”const title = await page.evaluate(() => document.title);const count = await page.locator("css:input").count();const exists = await page.exists("role:button[name='Submit']");const element = await page.$("css:button");const elements = await page.$$("css:li");evaluate takes an arrow function, serializes it, and runs it in the page. locator() returns a lazy Locator — see the Locator reference.
Waiting
Section titled “Waiting”await page.waitForSelector("css:.loaded");await page.waitForLoadState("networkidle");await page.waitForURL("**/dashboard");await page.waitFor("css:.modal"); // returns booleanawait page.waitForTimeout(2000); // prefer waitForSelector when possibleScreenshots
Section titled “Screenshots”await page.screenshot("./page.png");await page.screenshot(); // no file, just capturesRaw Chrome DevTools Protocol access:
const cookies = await page.cdp("Network.getCookies", {});await page.cdp("Network.clearBrowserCookies", {});