microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.04k stars 3.6k forks source link

[BUG] Incorrect service worker user agent with device emulation #5237

Open arjunattam opened 3 years ago

arjunattam commented 3 years ago

Context:

When device emulation is used, navigator.userAgent returns different values on page and service worker.

const { chromium, devices } = require('playwright');

(async() => {
  const browser = await chromium.launch({ headless: false });
  const context = await browser.newContext({...devices['Pixel 2']});
  const page = await context.newPage();
  await page.goto('https://googlechrome.github.io/samples/service-worker/basic/');
  console.log(await page.evaluate(() => navigator.userAgent));
  const worker = context.serviceWorkers()[0];
  console.log(await worker.evaluate(() => navigator.userAgent));
  await browser.close();
})();

Actual response

Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4392.0 Safari/537.36

Expected: same user agent in both lines

brnbs commented 2 years ago

Is there any update on this?

SkReD commented 1 year ago

Meet this too. With hard refresh user agent in service worker become same as in navigator but even after that with usual refresh user agent in service worker still differs

jean-francois-labbe commented 1 year ago

I'm also facing this issue. Have you found any workaround ?

I wonder how selenium solves this issue as all my serviceWorker tests are working with it.

Vivek-Kini commented 1 year ago

@dgozman : Do we have any updates on this please?

pavelfeldman commented 1 year ago

Why was this issue closed?

Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable.

Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated.

mxschmitt commented 3 months ago

Upstream bug: https://issues.chromium.org/issues/40236995