Skip to content

Set custom User-Agent string for Puppeteer as workaround #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ exports.extractCss = async url => {
})
const page = await browser.newPage()

// Set an explicit UserAgent, because the default UserAgent string includes something like
// `HeadlessChrome/88.0.4298.0` and some websites/CDN's block that with a HTTP 403
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0')

// Start CSS coverage. This is the meat and bones of this module
await page.coverage.startCSSCoverage().catch(() => {})

Expand Down
5 changes: 0 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ The folks from [CSS Stats](https://cssstats.com/) have created [get-css](https:/

This package uses an actual browser under the hood to get all the CSS and exposes an HTTP endpoint that accepts a url to get the CSS from.

## Local testing

I have no idea how local testing for Now is supposed to work, so I created a tiny HTTP server in `dev.js` that calls the actual function that gets deployed.
Run `ENV=dev npm run dev` to run a local version of the function for local testing.

## Credits

- This repo is pretty much an exact copy of [this example from Zeit](https://github.com/zeit/now-examples/tree/master/puppeteer-screenshot).
Expand Down