Skip to content

BrowserPage.setViewport()

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

Sets the page viewport.

Signature

setViewport(viewport: IBrowserPageViewport): void;

Parameters

Parameter Type Description
viewport IBrowserPageViewport Viewport object

Returns

void

Example

import { Browser } from "happy-dom";

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

page.setViewport({
   width: 1920,
   height: 1080,
   devicePixelRatio: 2
});

// Outputs: 1920
console.log(page.mainFrame.window.innerWidth);

await browser.close();
Clone this wiki locally