-
-
Notifications
You must be signed in to change notification settings - Fork 219
BrowserPage.evaluate()
David Ortner edited this page Feb 22, 2025
·
8 revisions
Evaluates code or a VM Script in the context of the page.
evaluate(script: string | Script): any;
any
import { Browser } from "happy-dom";
const browser = new Browser();
const page = browser.newPage();
page.evaluate('document.body.innerHTML = "<span>hello world</span>";');
// Outputs: "hello world"
console.log(page.mainFrame.document.querySelector('span').innerText);
page.evaluate(new Script('document.body.innerHTML = "<span>Hello world!!!!</span>";'));
// Outputs: "Hello world!!!!"
console.log(page.mainFrame.document.querySelector('span').innerText);
await browser.close();
Help Packages