ConsoleMessage
ConsoleMessage オブジェクトは、Page.Console イベントを介してページによってディスパッチされます。ページにログ記録されたコンソールメッセージごとに、Playwright コンテキストに対応するイベントがあります。
// 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
メソッド
Args
v1.9より前に追加console 関数呼び出しに渡された引数のリストです。Page.Console も参照してください。
使用法
ConsoleMessage.Args
戻り値
Location
v1.9より前に追加リソースの URL と、そのリソース内の 0 から始まる行番号と列番号が URL:行:列 の形式でフォーマットされます。
使用法
ConsoleMessage.Location
戻り値
Page
追加バージョン: v1.34このコンソールメッセージを生成したページ(もしあれば)。
使用法
ConsoleMessage.Page
戻り値
Text
v1.9より前に追加コンソールメッセージのテキスト。
使用法
ConsoleMessage.Text
戻り値
Type
v1.9より前に追加以下のいずれかの値: 'log', 'debug', 'info', 'error', 'warning', 'dir', 'dirxml', 'table', 'trace', 'clear', 'startGroup', 'startGroupCollapsed', 'endGroup', 'assert', 'profile', 'profileEnd', 'count', 'timeEnd'。
使用法
ConsoleMessage.Type
戻り値