Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Network Monitoring

ariya edited this page Sep 23, 2012 · 18 revisions

Because PhantomJS permits the inspection of network traffic, it is suitable to build various analysis on the network behavior and performance.

All the resource requests and responses can be sniffed using onResourceRequested and onResourceReceived. A very simple to log every request and response is illustrated in the example script netlog.js:

var page = require('webpage').create();
page.onResourceRequested = function (request) {
    console.log('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
    console.log('Receive ' + JSON.stringify(response, undefined, 4));
};
page.open(url);

By collecting the data and reformatting it, another example, netsniff.js, exports the network traffic in HAR format. Use HAR viewer to visualize the result and get the waterfall diagram.

The following shows an examplary waterfall diagram obtained from BBC website:

Waterfall Diagram

Clone this wiki locally