Skip to content

BrowserPage.evaluate()

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

Evaluates code or a VM Script in the context of the page.

Signature

execute(): any;

Returns

any

Example

import { Browser } from "happy-dom";

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

page.execute('document.body.innerHTML = "<span>hello world</span>";');

// Outputs: "hello world"
console.log(page.mainFrame.document.querySelector('span').innerText);

page.execute(new Script('document.body.innerHTML = "<span>Hello world!!!!</span>";'));

// Outputs: "Hello world!!!!"
console.log(page.mainFrame.document.querySelector('span').innerText);

await browser.close();
Clone this wiki locally