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
  • Docs
  • MCP
  • CLI
  • API
  • Node.js
  • Python
  • Java
  • .NET
  • API reference
  • Classes
  • APIRequestContext
  • APIResponse
  • Browser

This view

  • Original page
  • New address

GeezerVison is showing playwright.dev — ConsoleMessage | Playwright

This is unreleased documentation for Playwright Next version.
For up-to-date documentation, see the latest version (stable).
Version: Next

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.

// Listen for all console logs
page.on('console', msg => console.log(msg.text()));

// Listen for all console events and handle errors
page.on('console', msg => {
if (msg.type() === 'error')
console.log(`Error text: "${msg.text()}"`);
});

// Get the next console log
const msgPromise = page.waitForEvent('console');
await page.evaluate(() => {
console.log('hello', 42, { foo: 'bar' }); // Issue console.log inside the page
});
const msg = await msgPromise;

// Deconstruct console log arguments
await msg.args()[0].jsonValue(); // hello
await msg.args()[1].jsonValue(); // 42

Methods​

args​

Added before v1.9 consoleMessage.args

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

Usage

consoleMessage.args();

Returns

  • Array<JSHandle>#

location​

Added before v1.9 consoleMessage.location

Usage

consoleMessage.location();

Returns

  • Object#
    • url string

      URL of the resource.

    • line number

      0-based line number in the resource.

    • column number

      0-based column number in the resource.

    • lineNumber number

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

    • columnNumber number

      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

consoleMessage.page();

Returns

  • null | Page#

text​

Added before v1.9 consoleMessage.text

The text of the console message.

Usage

consoleMessage.text();

Returns

  • string#

timestamp​

Added in: v1.59 consoleMessage.timestamp

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

Usage

consoleMessage.timestamp();

Returns

  • number#

type​

Added before v1.9 consoleMessage.type

Usage

consoleMessage.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 consoleMessage.page().

Usage

consoleMessage.worker();

Returns

  • null | Worker#
  • Methods
    • args
    • location
    • page
    • text
    • timestamp
    • type
    • worker
You are visitor 01402775 — 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.