English · Java
Appearance
English · Java
Appearance
ConsoleMessage objects are dispatched by page via the page.onConsoleMessage() event. For each console message logged in the page there will be corresponding event in the Playwright context.
// Listen for all console messages and print them to the standard output.
page.onConsoleMessage(msg -> System.out.println(msg.text()));
// Listen for all console messages and print errors to the standard output.
page.onConsoleMessage(msg -> {
if ("error".equals(msg.type()))
System.out.println("Error text: " + msg.text());
});
// Get the next console message
ConsoleMessage msg = page.waitForConsoleMessage(() -> {
// Issue console.log inside the page
page.evaluate("console.log('hello', 42, { foo: 'bar' });");
});
// Deconstruct console.log arguments
msg.args().get(0).jsonValue(); // hello
msg.args().get(1).jsonValue(); // 42List of arguments passed to a console function call. See also page.onConsoleMessage().
Returns
Array<JSHandle>URL of the resource followed by 0-based line and column numbers in the resource formatted as URL:line:column.
Returns
stringThe page that produced this console message, if any.
Returns
null | PageThe text of the console message.
Returns
stringThe timestamp of the console message in milliseconds since the Unix epoch.
Returns
floatOne of the following values: 'log', 'debug', 'info', 'error', 'warning', 'dir', 'dirxml', 'table', 'trace', 'clear', 'startGroup', 'startGroupCollapsed', 'endGroup', 'assert', 'profile', 'profileEnd', 'count', 'timeEnd'.
Returns
stringThe web worker or service worker that produced this console message, if any. Note that console messages from web workers also have non-null consoleMessage.page().
Returns
null | Worker