Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion packages/puppeteer-core/src/cdp/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ export class CdpBrowser extends BrowserBase {
}

override async newPage(): Promise<Page> {
return await this.#defaultContext.newPage();
const page = await this.#defaultContext.newPage();
await page.setUserAgent(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to do the same thing in BrowserContext. I think that both Browser.newPage and BrowserContext.newPage end up calling https://github.com/cloudflare/puppeteer/blob/19e40c556e10b8d259df11f0dc32ea4f1a495789/packages/puppeteer-core/src/cdp/Browser.ts#L346C1-L347C1.

);
return page;
}

async _createPageInContext(contextId?: string): Promise<Page> {
Expand Down
12 changes: 12 additions & 0 deletions test/src/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
describe('Page', function () {
setupTestBrowserHooks();

describe('Useragent', function () {
it('should have a default user agent set', async () => {
const {context} = await getTestState();
const newPage = await context.newPage();
const userAgent = await newPage.evaluate(() => navigator.userAgent);

Check failure on line 30 in test/src/page.spec.ts

View workflow job for this annotation

GitHub Actions / [Required] Inspect code

Expected block statement surrounding arrow body
assert.strictEqual(
userAgent,
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
);
});
});

describe('Page.close', function () {
it('should reject all promises when page is closed', async () => {
const {context} = await getTestState();
Expand Down
Loading