O'Reilly logo

PhantomJS Cookbook by Rob Friesel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recording debugger messages

This recipe introduces the onConsoleMessage callback, discusses how to intercept debugger messages on the web page, and forwards them to the command-line output. The onConsoleMessage demonstration serves as an introduction to the other callbacks (for example, onAlert, onLoadFinished, onResourceReceived, and so on) that can be attached to webpage instances, while also providing a frame of reference for working with them.

Getting ready

To run this recipe, we will need a script that loads a web page, and then we will need JavaScript that executes in the context of that web page and writes messages to its console object.

The script in this recipe is available in the downloadable code repository as recipe06.js under chapter03 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required