Skip to content

Instantly share code, notes, and snippets.

@fbrnc

fbrnc/resources.js

Created Nov 17, 2015
Embed
What would you like to do?
PhantomJS snippet that lists (and counts) all domains that are being accessed during a request
var page = require('webpage').create();
function extractDomain(url) {
var domain = (url.indexOf("://") > -1) ? url.split('/')[2] : url.split('/')[0];
domain = domain.split(':')[0];
return domain;
}
var domains = {};
page.onResourceRequested = function(requestData, networkRequest) {
var domain = extractDomain(requestData.url);
if (domains.hasOwnProperty(domain)) {
domains[domain]++;
} else {
domains[domain]=1;
}
};
page.open('http://magento.com', function() {
for (var domain in domains) {
console.log(domain, domains[domain]);
}
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment