Skip to content

Browser

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

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({
   navigator: {
      userAgent: 'Mozilla/5.0 (X11; Linux x64) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/2.0.0'
   }
});
const page = browser.newPage();

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

await browser.close();

Constructor

Parameter Type Description
options? object Browser options.
options.settings? IOptionalBrowserSettings Browser settings.
options.console? Console Console object. Each context will use an instance of VirtualConsole by default if not specified.

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.
Clone this wiki locally