question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I set useragent like puppeteer?

See original GitHub issue

I found this plugin while developing E2E server using puppeteer, So I considering replace it with this plugin.

But, I can’t find page.setUserAgent function like puppeteer. My company use app using webview, So we add to the flag in useragent to identify it is an app.

So, Can I set useragent or add useragent use page object? If I can not add useragent, Are there any plans to add an useragent?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
aslushnikovcommented, Jan 28, 2020

Playwright’s cornerstone is a “browser context” - all the setup goes through it. You can create a new browser context with a given user agent - and all pages inside of it will inherit it:

const {webkit} = require('playwright');
(async () => {
  const browser = await webkit.launch();
  // Create a new incognito browser context with a proper user agent
  const context = await browser.newContext({
    userAgent: 'my-user-agent'
  });
  // Now the page will have the user agent 
  const page = await context.newPage('https://example.com');
  console.log(await page.evaluate(() => navigator.userAgent));
})();

Check out docs for all the info.

3reactions
yury-scommented, Mar 23, 2021

It works just fine for me:

  const context = await browser.newContext({userAgent: 'foo'});
  const p = await context.newPage();
  await p.goto('https://example.com');
  console.log(await p.evaluate('navigator.userAgent'));
  await p.goto('https://bing.com');
  console.log(await p.evaluate('navigator.userAgent'));

Please open a new issue with failing code snippet if it fails for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set User-Agent header with Puppeteer JS and not fail
We don't need to start Puppeteer. We can open devtools and go to “Network conditions” tab. There, set the User-Agent to Internet Explorer...
Read more >
Modify Puppeteer User Agent - Brian Childress
If we change the string in Puppeteer, we can “appear” as if we're a different user or device. New User-Agent: 1, "Mozilla/5.0 (Macintosh;...
Read more >
puppeteer.Page.setUserAgent JavaScript and Node.js code ...
Specifies the User-Agent used in this page. Most used puppeteer functions. launch. The method launches a browser instance with given arguments. The browser...
Read more >
Puppeteer browser useragent list - Stack Overflow
setUserAgent(randomAgent); will be just fine. const browser = await puppeteer.getBrowserInstance(port); const randomReferer = referers[Math.
Read more >
Setting a user agent – Browserless Docs
If you're using our APIs like /screenshot, /content, /pdf, or /scrape, you can also set the user agent in the body of your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found