Skip to content

Instantly share code, notes, and snippets.

@geotheory
Forked from anaynayak/url_requests.js
Created January 31, 2018 11:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geotheory/9666aba4caed4f723b75ff8ac1418d96 to your computer and use it in GitHub Desktop.
Save geotheory/9666aba4caed4f723b75ff8ac1418d96 to your computer and use it in GitHub Desktop.
phantom.js script to log all http requests from a page
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: phantomjs url_requests.js http://some.url.com');
phantom.exit(1);
} else {
address = system.args[1];
var logUrl = function (req) {
console.log(req.url);
};
page.onResourceRequested = logUrl;
page.onResourceReceived = logUrl;
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
phantom.exit();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment