Skip to content

BrowserFrame.evaluate()

David Ortner edited this page Jan 12, 2024 · 2 revisions

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

Signature

execute(): any;

Returns

any

Example

import { Browser } from "happy-dom";

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

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

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

page.mainFrame.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