Skip to content

BrowserPage

David Ortner edited this page Jan 21, 2025 · 13 revisions

BrowserPage represents a browser page (popup window or a tab).

Signature

class BrowserPage implements IBrowserPage

Properties

Property Modifiers Type Description
virtualConsolePrinter readonly VirtualConsolePrinter API for reading the output of the virtual console.
mainFrame readonly BrowserFrame Main frame.
context readonly BrowserContext Owner context.
console readonly Console | VirtualConsole Console object sent in to the constructor or a virtual console.
viewport readonly IBrowserPageViewport Viewport.
frames readonly BrowserFrame[] All frames associated with the page.
content string Page content HTML.
url string Page URL.

Methods

Method Return type Description
close() Promise<void> Closes the page.
waitUntilComplete() Promise<void> Waits for all ongoing operations to complete. This includes operations such as loading resources and executing scripts.
waitForNavigation() Promise<void> Waits for the page to be navigated after a link has been clicked or the page is redirected by a script. This is resolved when the HTML of the new URL has been loaded into the main frame.
abort() Promise<void> Aborts all ongoing operations.
evaluate() any Evaluates code or a VM Script in the page's context.
setViewport() void Sets the viewport.
goto() Promise<IResponse | null> Navigates the main frame to a URL. The promise is resolved after the content has been loaded into the window.
reload() Promise<IResponse | null> Reloads the page.

Example

import { Browser } from "happy-dom";

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

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

await browser.close();
Clone this wiki locally