Skip to content

Latest commit

 

History

History
228 lines (167 loc) · 9.63 KB

File metadata and controls

228 lines (167 loc) · 9.63 KB
id class-consolemessage
title ConsoleMessage

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import HTMLCard from '@site/src/components/HTMLCard';

ConsoleMessage objects are dispatched by page via the Page.Console 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.Console += (_, msg) => Console.WriteLine(msg.Text);

// Listen for all console messages and print errors to the standard output.
page.Console += (_, msg) =>
{
    if ("error".Equals(msg.Type))
        Console.WriteLine("Error text: " + msg.Text);
};

// Get the next console message
var waitForMessageTask = page.WaitForConsoleMessageAsync();
await page.EvaluateAsync("console.log('hello', 42, { foo: 'bar' });");
var message = await waitForMessageTask;
// Deconstruct console.log arguments
await message.Args.ElementAt(0).JsonValueAsync<string>(); // hello
await message.Args.ElementAt(1).JsonValueAsync<int>(); // 42

Methods

Args {#console-message-args}

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9consoleMessage.Args

List of arguments passed to a console function call. See also Page.Console.

Usage

ConsoleMessage.Args

Returns


Location {#console-message-location}

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9consoleMessage.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


Page {#console-message-page}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.34consoleMessage.Page

The page that produced this console message, if any.

Usage

ConsoleMessage.Page

Returns


Text {#console-message-text}

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9consoleMessage.Text

The text of the console message.

Usage

ConsoleMessage.Text

Returns


Timestamp {#console-message-timestamp}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.59consoleMessage.Timestamp

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

Usage

ConsoleMessage.Timestamp

Returns

  • [float]#

Type {#console-message-type}

<font size="2" style={{position: "relative", top: "-20px"}}>Added before v1.9consoleMessage.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


Worker {#console-message-worker}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.57consoleMessage.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