Skip to content

Instantly share code, notes, and snippets.

@DanNi0130
Created August 2, 2018 23:13
Show Gist options
  • Save DanNi0130/719445ee113323120b349b2c65c6f944 to your computer and use it in GitHub Desktop.
Save DanNi0130/719445ee113323120b349b2c65c6f944 to your computer and use it in GitHub Desktop.
const blockedResourceTypes = [
'image',
'media',
'font',
'texttrack',
'object',
'beacon',
'csp_report',
'imageset',
];
const skippedResources = [
'quantserve',
'adzerk',
'doubleclick',
'adition',
'exelator',
'sharethrough',
'cdn.api.twitter',
'google-analytics',
'googletagmanager',
'google',
'fontawesome',
'facebook',
'analytics',
'optimizely',
'clicktale',
'mixpanel',
'zedo',
'clicksor',
'tiqcdn',
];
page.on('request', request => {
const requestUrl = request._url.split('?')[0].split('#')[0];
if (
blockedResourceTypes.indexOf(request.resourceType()) !== -1 ||
skippedResources.some(resource => requestUrl.indexOf(resource) !== -1)
) {
request.abort();
} else {
request.continue();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment