Skip to main content
Version: 1.12.0

Verification

Console logs#

Console messages logged in the page can be brought into the Playwright context.

// Listen for all System.out.printlns
page.Console += (_, msg) => Console.WriteLine(msg.Text);
// Listen for all console events and handle errors
page.Console += (_, msg) =>
{
if ("error".Equals(msg.Type))
Console.WriteLine("Error text: " + msg.Text);
};
// Get the next System.out.println
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

API reference#


Page errors#

Listen for uncaught exceptions in the page with the pagerror event.

// Log all uncaught errors to the terminal
page.PageError += (_, exception) =>
{
Console.WriteLine("Uncaught exception: " + exception);
};

API reference#


Page events#

"requestfailed"#

"dialog" - handle alert, confirm, prompt#

page.RequestFailed += (_, request) =>
{
Console.WriteLine(request.Url + " " + request.Failure);
};

"popup" - handle popup windows#

var popup = await page.RunAndWaitForPopupAsync(async () =>
{
await page.ClickAsync("#open");
});

API reference#