📄 playwright-python/python/docs/api/class-consolemessage

File: class-consolemessage.md | Updated: 11/18/2025

Source: https://playwright.dev/python/docs/api/class-consolemessage

Skip to main content

On this page

ConsoleMessage objects are dispatched by page via the page.on("console") event. For each console message logged in the page there will be corresponding event in the Playwright context.

  • Sync

  • Async

    Listen for all console logspage.on("console", lambda msg: print(msg.text))# Listen for all console events and handle errorspage.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)# Get the next console logwith 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 argumentsmsg.args[0].json_value() # hellomsg.args[1].json_value() # 42

    Listen for all console logspage.on("console", lambda msg: print(msg.text))# Listen for all console events and handle errorspage.on("console", lambda msg: print(f"error: {msg.text}") if msg.type == "error" else None)# Get the next console logasync with page.expect_console_message() as msg_info: # Issue console.log inside the page await page.evaluate("console.log('hello', 42, { foo: 'bar' })")msg = await msg_info.value# Deconstruct print argumentsawait msg.args[0].json_value() # helloawait msg.args[1].json_value() # 42


Properties


args

Added before v1.9 consoleMessage.args

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

Usage

console_message.args

Returns


location

Added before v1.9 consoleMessage.location

Usage

console_message.location

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.


page

Added in: v1.34 consoleMessage.page

The page that produced this console message, if any.

Usage

console_message.page

Returns


text

Added before v1.9 consoleMessage.text

The text of the console message.

Usage

console_message.text

Returns


type

Added before v1.9 consoleMessage.type

Usage

console_message.type

Returns

  • "log" | "debug" | "info" | "error" | "warning" | "dir" | "dirxml" | "table" | "trace" | "clear" | "startGroup" | "startGroupCollapsed" | "endGroup" | "assert" | "profile" | "profileEnd" | "count" | "timeEnd"#

  • Properties