ConsoleMessage
ConsoleMessage objects are dispatched by page via the page.on('console') event. For each console messages logged in the page there will be corresponding event in the Playwright context.
// Listen for all console logs
page.on('console', msg => console.log(msg.text()))
// Listen for all console events and handle errors
page.on('console', msg => {
if (msg.type() === 'error')
console.log(`Error text: "${msg.text()}"`);
});
// Get the next console log
const [msg] = await Promise.all([
page.waitForEvent('console'),
// Issue console.log inside the page
page.evaluate(() => {
console.log('hello', 42, { foo: 'bar' });
}),
]);
// Deconstruct console log arguments
await msg.args[0].jsonValue() // hello
await msg.args[1].jsonValue() // 42
consoleMessage.args()
Added in: v1.8List of arguments passed to a console function call. See also page.on('console').
consoleMessage.location()
Added in: v1.8consoleMessage.text()
Added in: v1.8The text of the console message.
consoleMessage.type()
Added in: v1.8One of the following values: 'log', 'debug', 'info', 'error', 'warning', 'dir', 'dirxml', 'table', 'trace', 'clear', 'startGroup', 'startGroupCollapsed', 'endGroup', 'assert', 'profile', 'profileEnd', 'count', 'timeEnd'.