Skip to content
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

feat: set custom userAgent #1398

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fuhlig
Copy link
Contributor

@fuhlig fuhlig commented Mar 6, 2022

Motivation:

  • emulate userAgent if page parses UA
  • not polute analytics data by using custom userAgent that can be excluded from analytics
  • Playwright does not allow setting userAgent in onReady script via page.setUserAgent() like puppeteer does and needs to be set in browser context
    Can I set useragent like puppeteer? microsoft/playwright#697

Features:

  • set userAgent via scenario.userAgent or config.userAgent
  • for both Puppeteer & Playwright

Testing:

npm run ua-test -- --engine="puppeteer" --browser="chromium"
npm run ua-test -- --engine="puppeteer" --browser="firefox"

npm run ua-test -- --engine="playwright" --browser="chromium"
npm run ua-test -- --engine="playwright" --browser="firefox"
npm run ua-test -- --engine="playwright" --browser="webkit"

Examples

Playwright
Puppeteer

fuhlig added 4 commits March 4, 2022 17:41
Set custom userAgent via scenario or config via `userAgent`.
If no userAgent is set, the browser's default will be taken (via `''`)

[Playwright Docs: userAgent](https://playwright.dev/docs/emulation#user-agent)
Set custom userAgent via scenario or config via `userAgent`.
If no userAgent is set, the browser's default will be taken (via `''`)

[Puppeteer Docs: setUserAgent](https://pptr.dev/#?product=Puppeteer&show=api-pagesetuseragentuseragent-useragentmetadata)
- add npm script `ua-test`
- add test config

usage:
```
npm run ua-test -- --engine="puppeteer|playwright" --browser="chromium|firefox|webkit"
```

examples:
```
npm run ua-test -- --engine="puppeteer" --browser="chromium"
npm run ua-test -- --engine="puppeteer" --browser="firefox"

npm run ua-test -- --engine="playwright" --browser="chromium"
npm run ua-test -- --engine="playwright" --browser="firefox"
npm run ua-test -- --engine="playwright" --browser="webkit"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant