-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Can I set useragent like puppeteer? #697
Comments
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. |
Thx for my question. It helped a lot 👍 |
If the user agent is set with newContext() or newPage(), it's lost on navigation - goto() or click(). Only launchOptions and args works for me. |
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. |
Thanks for your response. I've described it here: #5935 |
@aslushnikov Is there a way to do this, but still inherit the global config settings in the new context? I noticed that by calling |
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?
The text was updated successfully, but these errors were encountered: