Skip to content

Instantly share code, notes, and snippets.

@fbrnc
Created November 17, 2015 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbrnc/3db1b77388fbc6e78c6b to your computer and use it in GitHub Desktop.
Save fbrnc/3db1b77388fbc6e78c6b to your computer and use it in GitHub Desktop.
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