Skip to content

Instantly share code, notes, and snippets.

@juampynr
Last active August 29, 2015 14:17
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 juampynr/312a0031e3dbaf607609 to your computer and use it in GitHub Desktop.
Save juampynr/312a0031e3dbaf607609 to your computer and use it in GitHub Desktop.
CasperJS skip third party requests
/**
* Skip third party resources from being requested.
*
* Usage: add this file to casper js at the --includes option.
* Edit the array of URLs to skip.
* You can find out which third party requests your pages are making
* by adding the option --log-level=debug to the casperjs command.
*/
casper.on('resource.requested', function(requestData, request) {
// List of URLs to skip. Entering part of a hostname or path is OK.
var blackList = [
'b3.mookie1.com',
'googleads.g.doubleclick.net',
'googlesyndication'
];
var blackListLength = blackList.length;
// If a match is found, abort the request.
for (var i = 0; i < blackListLength; i++) {
if (requestData.url.indexOf(blackList[i]) > -1) {
casper.log('Skipped: ' + requestData.url, 'info');
request.abort();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment