Skip to main content
Version: 1.22


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", lambda msg: print(msg.text))

# Listen for all console events and handle errors
page.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)

# Get the next console log
with page.expect_console_message() as msg_info:
# Issue console.log inside the page
page.evaluate("console.log('hello', 42, { foo: 'bar' })")
msg = msg_info.value

# Deconstruct print arguments
msg.args[0].json_value() # hello
msg.args[1].json_value() # 42


List of arguments passed to a console function call. See also page.on("console").


  • returns: <Dict>#
    • url <str> URL of the resource.
    • lineNumber <int> 0-based line number in the resource.
    • columnNumber <int> 0-based column number in the resource.


The text of the console message.


One of the following values: 'log', 'debug', 'info', 'error', 'warning', 'dir', 'dirxml', 'table', 'trace', 'clear', 'startGroup', 'startGroupCollapsed', 'endGroup', 'assert', 'profile', 'profileEnd', 'count', 'timeEnd'.