Skip to content

BrowserContext

David Ortner edited this page Jan 12, 2024 · 12 revisions

BrowserContext represents a context where data such as cache and cookies can be shared between its pages.

Signature:

class BrowserContext implements IBrowserContext

Example

import { Browser } from "happy-dom";

const browser = new Browser();
const context = browser.newIncognitoContext();
const page = context.newPage();

await page.goto("https://example.com");

await browser.close();

Properties

Property Modifiers Type Description
pages readonly BrowserPage[] Pages.
browser readonly Browser Owner Browser.
cookieContainer readonly CookieContainer Cookie container.
responseCache readonly ResponseCache Response cache.
preflightResponseCache readonly PreflightResponseCache Preflight response cache.

Methods

Method Return type Description
close() Promise<void> Closes the context.
waitUntilComplete() Promise<void> Waits for all ongoing operations to complete. This includes operations done inside loaded pages, such as loading resources and executing scripts.
abort() Promise<void> Aborts all ongoing operations.
newPage() BrowserPage Creates a new page.
Clone this wiki locally