Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/pptr/src/Browser.ts>BrowserContext

Headless Chrome Deno API
Latest
class BrowserContext
extends EventEmitter
import { BrowserContext } from "https://deno.land/x/pptr@1.2.0/src/Browser.ts";

BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method Browser.newPage | Browser.newPage creates a page in the default browser context.

Examples

Example 1

// Create a new incognito browser context
const context = await browser.createIncognitoBrowserContext();
// Create a new page inside context.
const page = await context.newPage();
// ... do stuff with page ...
await page.goto('https://example.com');
// Dispose context once it's no longer needed.
await context.close();

Constructors

new
BrowserContext(
connection: Connection,
browser: Browser,
contextId?: string,
)

Properties

private
_browser: Browser
private
_connection: Connection
private
optional
_id: string

Methods

The browser this browser context belongs to.

clearPermissionOverrides(): Promise<void>

Clears all permission overrides for the browser context.

close(): Promise<void>

Closes the browser context. All the targets that belong to the browser context will be closed.

isIncognito(): boolean

Returns whether BrowserContext is incognito. The default browser context is the only non-incognito browser context.

newPage(): Promise<Page>

Creates a new page in the browser context.

overridePermissions(origin: string, permissions: string[]): Promise<void>
pages(): Promise<Page[]>

An array of all pages inside the browser context.

An array of all active targets inside the browser context.

waitForTarget(predicate: (x: Target) => boolean, options?: { timeout?: number; }): Promise<Target>

This searches for a target in this specific browser context.