Skip to content
Maciej Brencz edited this page Nov 5, 2013 · 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. Refer to PhantomJS events docs.

pageBeforeOpen

fired before the page is requested.

pageOpen

fired just after page is requested.

loadStarted

Loading of the page has just started.

init

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.

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) { /* ... */ });

beforeSend

Emitted just before HTTP request is sent.

phantomas.on('beforeSend', function(entry, res) {
  entry.block(); // call to block the request
});

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.

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

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

jserror

Emitted when JavaScript error occurs

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

alert

Emitted when alert() function is called

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

confirm

Emitted when confirm() function is called

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

prompt

Emitted when prompt() function is called

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