Maciej Brencz edited this page Apr 1, 2017 · 9 revisions

phantomas core uses EventEmitter, well known from nodejs, to trigger events each module can attach handlers to via phantomas.on() function.

Please note that not all events are exposed to npm module via ipc events (these events are marked as internal).

Generic events

In the order of triggering. Refer to PhantomJS events docs.

pageBeforeOpen internal

fired before the page is requested.

pageOpen internal

fired just after page is requested.

loadStarted internal

Loading of the page has just started.

init internal

Not fired when in --disable-js mode

PhantomJS page was created, but URL is not yet loaded. You can now try to inject custom JavaScript code in the page environment.


Reports the progress of loading the page

phantomas.on('progress', function(progress, incr) { /* ... */ });

loadFinished internal

Page is successfully loaded.

loadFailed internal

Page failed to load.

report internal

Triggered just before the final report is generated. The last chance to add or modify a metric.

HTTP traffic


HTTP request was sent (additional request data is passed to the listener).

phantomas.on('send', function(entry, res) { /* ... */ });


The whole response was received (additional response data is passed to the listener).

phantomas.on('recv', function(entry, res) { /* ... */ });


The base64-encoded response was received (additional response data is passed to the listener).

phantomas.on('base64recv', function(entry, res) { /* ... */ });

Browser events

consoleLog internal

Emitted when console.log is called from within the page.

console.log('%s: %s', 'foo', 123);

phantomas.on('consoleLog', function(msg, data) {
  // msg = 'foo: 123'
  // data = ['%s: %s', 'foo', 123]

jserror internal

Emitted when JavaScript error occurs

phantomas.on('jserror', function(msg, trace) { /* ... */ });

alert internal

Emitted when alert() function is called

phantomas.on('alert', function(msg) { /* ... */ });

confirm internal

Emitted when confirm() function is called

phantomas.on('confirm', function(msg) { /* ... */ });

prompt internal

Emitted when prompt() function is called

phantomas.on('prompt', function(msg) { /* ... */ });

npm module events

When you're using phantomas npm module to run phantomas from within Node.js code the following events can be bound to:

$ ./examples/promise.js | grep "Milestone reached"
Milestone reached: responseEnd
Milestone reached: domInteractive
Milestone reached: domReady
Milestone reached: domComplete


run.on('milestone', function(milestone) {
        console.log('Milestone reached: %s', milestone);