Verification
#
Console logsConsole messages logged in the page can be brought into the Playwright context.
// Listen for all console logspage.on('console', msg => console.log(msg.text()))
// Listen for all console events and handle errorspage.on('console', msg => { if (msg.type() === 'error') console.log(`Error text: "${msg.text()}"`);});
// Get the next console logconst [msg] = await Promise.all([ page.waitForEvent('console'), // Issue console.log inside the page page.evaluate(() => { console.log('hello', 42, { foo: 'bar' }); }),]);
// Deconstruct console log argumentsawait msg.args[0].jsonValue() // helloawait msg.args[1].jsonValue() // 42
#
API reference#
Page errorsListen for uncaught exceptions in the page with the pagerror
event.
// Log all uncaught errors to the terminalpage.on('pageerror', exception => { console.log(`Uncaught exception: "${exception}"`);});
// Navigate to a page with an exception.await page.goto('data:text/html,<script>throw new Error("Test")</script>');
#
API reference#
Page events"requestfailed"
#
page.on('requestfailed', request => { console.log(request.url() + ' ' + request.failure().errorText);});
"dialog"
- handle alert, confirm, prompt#
page.on('dialog', dialog => { dialog.accept();});
"popup"
- handle popup windows#
const [popup] = await Promise.all([ page.waitForEvent('popup'), page.click('#open')]);