File: class-consolemessage.md | Updated: 11/18/2025
On this page
ConsoleMessage objects are dispatched by page via the Page.onConsoleMessage(handler) 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 messageConsoleMessage msg = page.waitForConsoleMessage(() -> { // Issue console.log inside the page page.evaluate("console.log('hello', 42, { foo: 'bar' });");});// Deconstruct console.log argumentsmsg.args().get(0).jsonValue(); // hellomsg.args().get(1).jsonValue(); // 42
Methods
Added before v1.9 consoleMessage.args
List of arguments passed to a console function call. See also Page.onConsoleMessage(handler)
.
Usage
ConsoleMessage.args();
Returns
Added before v1.9 consoleMessage.location
URL of the resource followed by 0-based line and column numbers in the resource formatted as URL:line:column.
Usage
ConsoleMessage.location();
Returns
Added in: v1.34 consoleMessage.page
The page that produced this console message, if any.
Usage
ConsoleMessage.page();
Returns
Added before v1.9 consoleMessage.text
The text of the console message.
Usage
ConsoleMessage.text();
Returns
Added before v1.9 consoleMessage.type
One of the following values: 'log', 'debug', 'info', 'error', 'warning', 'dir', 'dirxml', 'table', 'trace', 'clear', 'startGroup', 'startGroupCollapsed', 'endGroup', 'assert', 'profile', 'profileEnd', 'count', 'timeEnd'.
Usage
ConsoleMessage.type();
Returns