Interface IConsoleMessage
- Namespace
- Microsoft.Playwright
- Assembly
- Microsoft.Playwright.dll
IConsoleMessage objects are dispatched by page via the 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
public interface IConsoleMessage
Properties
Args
List of arguments passed to a console
function call. See also Console.
IReadOnlyList<IJSHandle> Args { get; }
Property Value
Location
URL of the resource followed by 0-based line and column numbers in the resource
formatted as URL:line:column
.
string Location { get; }
Property Value
Page
The page that produced this console message, if any.
IPage? Page { get; }
Property Value
Text
The text of the console message.
string Text { get; }
Property Value
Type
One of the following values: 'log'
, 'debug'
, 'info'
, 'error'
,
'warning'
, 'dir'
, 'dirxml'
, 'table'
, 'trace'
,
'clear'
, 'startGroup'
, 'startGroupCollapsed'
, 'endGroup'
,
'assert'
, 'profile'
, 'profileEnd'
, 'count'
, 'timeEnd'
.
string Type { get; }