Skip to content
David Ortner edited this page Feb 21, 2024 · 5 revisions

Window represents a window instance detached from a Browser.

Signature:

class Window extends BrowserWindow implements IWindow

Example

import { Window } from 'happy-dom';

const window = new Window({
    url: 'https://localhost:8080',
    height: 1920,
    width: 1080
    settings: {
        navigator: {
            userAgent: 'Mozilla/5.0 (X11; Linux x64) AppleWebKit/537.36 (KHTML, like Gecko) HappyDOM/2.0.0'
        }
    }
});
const document = window.document;

document.body.innerHTML = '<div class="container"></div>';

const container = document.querySelector('.container');
const button = document.createElement('button');

container.appendChild(button);

// Outputs "<div class="container"><button></button></div>"
console.log(document.body.innerHTML);

// Close window
await window.happyDOM.close();

Constructor

Parameter Type Description
options? object Window options.
options.url? string URL of the page to load.
options.height? number Height of the window.
options.width? number Width of the window.
options.console? Console Console instance to use. Defaults to an instance of VirtualConsole.
options.settings? IOptionalBrowserSettings Browser settings.

Properties

Property Modifiers Type Description
happyDOM readonly DetachedWindowAPI API for communicating with the underlying browser when inside a detached Window.
Clone this wiki locally