Last active
August 29, 2015 14:17
-
-
Save juampynr/312a0031e3dbaf607609 to your computer and use it in GitHub Desktop.
CasperJS skip third party requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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