onConsole property

Stream<ConsoleMessage> onConsole

Emitted when JavaScript within the page calls one of console API methods, e.g. console.log or console.dir. Also emitted if the page throws an error or a warning.

The arguments passed into console.log appear as arguments on the event handler.

An example of handling console event:

page.onConsole.listen((msg) {
  for (var i = 0; i < msg.args.length; ++i) {
    print('$i: ${msg.args[i]}');
  }
});
await page.evaluate("() => console.log('hello', 5, {foo: 'bar'})");

Implementation

Stream<ConsoleMessage> get onConsole => _onConsoleController.stream;