Skip to content

Browser

David Ortner edited this page Jan 11, 2024 · 30 revisions

Browser

Browser represents an instance of a Happy DOM browser.

Signature:

class Browser implements IBrowser

Example

import { Browser } from "happy-dom";

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

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

await browser.close();

Properties

Name Modifiers Type Description
contexts readonly BrowserContext[] Browser contexts. Defaults to one main context.
settings readonly IBrowserSettings Browser settings. The settings can be modified runtime.
console readonly Console Console object sent in to the constructor.
defaultContext readonly BrowserContext Default context.

Methods

Name Return type Description
close() Promise<void> Closes the browser.
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.
newIncognitoContext() BrowserContext Creates a new incognito context.
newPage() BrowserPage Creates a new page.
Browser represents an instance of a Happy DOM browser. The API is similar to the API for Puppeteer and Playwright.

Signature:

class Browser implements IBrowser

Example

import { Browser } from 'happy-dom';

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

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

await browser.close();

Properties

Name Modifiers Type Description
contexts readonly [BrowserContext](https://github.com/capricorn86/happy-dom/wiki/BrowserContext)[] Browser contexts. Defaults to one main context.
settings readonly [IBrowserSettings](https://github.com/capricorn86/happy-dom/wiki/IBrowserSettings) Browser settings. The settings can be modified runtime.
console readonly Console Console object sent in to the constructor.
defaultContext readonly BrowserContext Default context.

Methods

Name Return type Description
close() Promise<void> Closes the browser.
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.
newIncognitoContext() BrowserContext Creates a new incognito context.
newPage() BrowserPage Creates a new page.

Clone this wiki locally