Replies: 1 comment 1 reply
-
|
Hi @Nashorn! You can listen for console messages of a page with the VirtualConsolePrinter. import { Browser } from "happy-dom";
const browser = new Browser();
const page = browser.newPage();
const messages = [];
page.virtualConsolePrinter.addEventListener('print', () => {
messages.push(page.virtualConsolePrinter.readAsString());
});
// Do something with console messages
console.log(messages);I'm working on a solution in #1730, which will make it possible to intercept the Window object before the document content has been loaded. This will make it possible to listen for the Window error event. E.g. const browser = new Browser({
settings: {
navigation: {
beforeContentCallback: (window) => {
window.addEventListener('error', (event) => {
// Do something with error
});
}
}
}
});
const page = browser.newPage();
await page.goto('https://www.example.com');or await page.goto('https://www.example.com', {
beforeContentCallback: (window) => {
window.addEventListener('error', (event) => {
// Do something with error
});
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How can HappyDOM be used to intercept the console messages of a webpage being loaded?
Beta Was this translation helpful? Give feedback.
All reactions