Created
August 2, 2018 23:51
-
-
Save DanNi0130/747db9f640d7011446cf4c17ee2d2d15 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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', | |
]; | |
const page = await browser.newPage(); | |
await page.setRequestInterception(true); | |
await page.setUserAgent(userAgent); | |
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(); | |
} | |
}); | |
const response = await page.goto(url, { | |
timeout: 25000, | |
waitUntil: 'networkidle2', | |
}); | |
if (response._status < 400) { | |
await page.waitFor(3000); | |
let html = await page.content(); | |
return html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment