Skip to content

Commit 6182aa2

Browse files
authored
Set custom User-Agent string for Puppeteer as workaround for websites that block Puppeteer when HeadlessChrome is present in the UA string. (#42)
1 parent 098a7b2 commit 6182aa2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module.exports = async (url, {waitUntil = 'networkidle0', origins = 'exclude'} =
2020

2121
// Create a new page and navigate to it
2222
const page = await browser.newPage()
23+
24+
// Set an explicit UserAgent, because the default UserAgent string includes something like
25+
// `HeadlessChrome/88.0.4298.0` and some websites/CDN's block that with a HTTP 403
26+
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0')
2327
await page.coverage.startCSSCoverage()
2428
url = normalizeUrl(url, {stripWWW: false})
2529
const response = await page.goto(url, {waitUntil})

0 commit comments

Comments
 (0)