Skip to content
David Ortner edited this page Oct 16, 2024 · 9 revisions

Window represents a window instance detached from a Browser.

Signature:

class Window extends BrowserWindow

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 Default value Description
options? object Window options.
options.url? string about:blank URL of the page to load.
options.height? number 768 Height of the window.
options.width? number 1024 Width of the window.
options.console? Console Instance of VirtualConsole Console instance to use.
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