diff --git a/.github/workflows/cf_test_full.yml b/.github/workflows/cf_test_full.yml index 5857ab246..adcaddd22 100644 --- a/.github/workflows/cf_test_full.yml +++ b/.github/workflows/cf_test_full.yml @@ -1,4 +1,4 @@ -name: "Puppeteer for Cloudflare - Full Tests" +name: 'Puppeteer for Cloudflare - Full Tests' on: workflow_dispatch: diff --git a/.github/workflows/cf_test_smoke.yml b/.github/workflows/cf_test_smoke.yml index 1de4f5d1b..8b34b233c 100644 --- a/.github/workflows/cf_test_smoke.yml +++ b/.github/workflows/cf_test_smoke.yml @@ -1,4 +1,4 @@ -name: "Puppeteer for Cloudflare - Smoke Tests" +name: 'Puppeteer for Cloudflare - Smoke Tests' on: push: diff --git a/packages/puppeteer-core/src/cdp/Browser.ts b/packages/puppeteer-core/src/cdp/Browser.ts index 599b800f0..17c12f2be 100644 --- a/packages/puppeteer-core/src/cdp/Browser.ts +++ b/packages/puppeteer-core/src/cdp/Browser.ts @@ -340,7 +340,11 @@ export class CdpBrowser extends BrowserBase { } override async newPage(): Promise { - 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' + ); + return page; } async _createPageInContext(contextId?: string): Promise { diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts index 8639198af..36e77a682 100644 --- a/test/src/page.spec.ts +++ b/test/src/page.spec.ts @@ -23,6 +23,21 @@ import {attachFrame, detachFrame, isFavicon, waitEvent} from './utils.js'; 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(); + process; + const userAgent = await newPage.evaluate(() => { + return navigator.userAgent; + }); + 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();