Skip to content
macbre edited this page Jul 16, 2012 · 10 revisions

phantomas core uses EventEmitter, well known from nodejs, to trigger events each module can attach handlers to.

Generic events

In the order of triggering

pageBeforeOpen

fired before the page is requested.

pageOpen

fired just after page is requested.

loadStarted

Loading of the page has just started.

init

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

loadFinished

Page is successfully loaded.

loadFailed

Page failed to load.

report

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

HTTP traffic

onResourceRequested

HTTP request was sent (request object from phantomJS is passed to the listener).

phantomas.on('onResourceRequested', function(res) {
  // ...
});

send

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

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

onResourceReceived

Chunk of the response was received (response object from phantomJS is passed to the listener).

phantomas.on('onResourceReceived', function(res) {
  // ...
});

recv

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

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

base64recv

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

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

Browser events

consoleLog

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

phantomas.on('consoleLog', function(msg) {
  // ...
});
Clone this wiki locally