GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Playwright for Python
  • Docs
  • API
  • Python
  • Node.js
  • Java
  • .NET
  • Community
  • Classes
  • APIRequestContext
  • APIResponse
  • Browser
  • BrowserContext
  • BrowserType

This view

  • Original page
  • New address

GeezerVison is showing playwright.dev — ConsoleMessage | Playwright Python

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 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
# 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
async 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 arguments
await msg.args[0].json_value() # hello
await 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

  • List[JSHandle]#

location​

Added before v1.9 consoleMessage.location

Usage

console_message.location

Returns

  • Dict#
    • url str

      URL of the resource.

    • line int

      0-based line number in the resource.

    • column int

      0-based column number in the resource.

    • lineNumber int

      0-based line number in the resource. Deprecated, use line instead.

    • columnNumber int

      0-based column number in the resource. Deprecated, use column instead.


page​

Added in: v1.34 consoleMessage.page

The page that produced this console message, if any.

Usage

console_message.page

Returns

  • NoneType | Page#

text​

Added before v1.9 consoleMessage.text

The text of the console message.

Usage

console_message.text

Returns

  • str#

timestamp​

Added in: v1.59 consoleMessage.timestamp

The timestamp of the console message in milliseconds since the Unix epoch.

Usage

console_message.timestamp

Returns

  • float#

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" | "time" | "timeEnd"#

worker​

Added in: v1.57 consoleMessage.worker

The web worker or service worker that produced this console message, if any. Note that console messages from web workers also have non-null console_message.page.

Usage

console_message.worker

Returns

  • NoneType | Worker#
  • Properties
    • args
    • location
    • page
    • text
    • timestamp
    • type
    • worker
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.