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
65.79k stars 3.58k forks source link

[Bug]: When using robotframework browserlibrary, "useragent" passed is not honored when using "webkit" browser #29629

Closed srajendran123 closed 6 months ago

srajendran123 commented 7 months ago

Version

NodeJS version: v18.17.1

Steps to reproduce

Desktop (please complete the following information): robotframework==6.1.1 robotframework-browser: 17.3.0 Browser: Webkit NodeJS version: v18.17.1 npm version: 9.6.7

Steps to reproduce: Invoke any url using browserlibrary from robotframework. Used the following code to invoke the app

New Persistent Context url=${url} browser=${execution_browser} userAgent=${userAgent} viewport=${viewport}

url - "https://pwa-br-us-a.qa.tillster.com/" browser - "webkit" user agent - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15 viewport - "{'width': 810, 'height': 1010}"

Issue:

When "webkit" is used, user agent provided in the script is not used when loading the application.

image

In the screenshot, mac useragent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15" is provided in the script . However, the application is loaded with Windows user agent, as the test is run on windows machine.

This is not an issue when using "chromium" browser. App is loaded with whatever useragent passed in the automation script.

Please let me know, if additional info is needed.

chromium.webm.zip webkit.webm.zip

Expected behavior

In the screenshot above, mac useragent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15" is provided in the script . Expected to see the same useragent for loading the app.

Actual behavior

In the screenshot, mac useragent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15" is provided in the script . However, the application is loaded with Windows user agent, as the test is run on windows machine.

Additional context

I opened a bug to Robotframework-browser support team and they suggested to open a ticket to playwright, as browser library passes that value to playwright without altering it.

https://github.com/MarketSquare/robotframework-browser/issues/3383

Environment

System:
    OS: macOS 12.6.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 143.58 MB / 32.00 GB
  Binaries:
    Node: 18.17.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.6.7 - /usr/local/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash
yury-s commented 7 months ago

I opened a bug to Robotframework-browser support team and they suggested to open a ticket to playwright, as browser library passes that value to playwright without altering it.

Can you / they provide a playwright example that we could run locally to reproduce the issue?

srajendran123 commented 7 months ago

@yury-s I wish I could help, but I am unfamiliar with using playwright. By passing a user agent, loading any url on webkit browser should reproduce the issue.

I am using the following code on the robotframework to reproduce the issue:

Settings Library Browser

Keywords load_the_application_on_non_incognito_mode New Persistent Context url=https://pwa-br-us-a.qa.tillster.com/ browser=webkit useragent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15

load_the_application_on_incognito_mode new browser browser=webkit headless=False new context userAgent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15' New Page url=https://pwa-br-us-a.qa.tillster.com/

In playwright, I think we could try the following code:

const { webkit } = require('playwright');

(async () => {
  // Launch the Webkit browser
  const browser = await webkit.launch();

  const context = await browser.newContext({
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15',
  });

  // Create a new page in the browser context and navigate to target URL
  const page = await context.newPage();
  await page.goto('https://httpbin.io/user-agent');    

  // Get the entire page content
  const pageContent = await page.content();
  console.log(pageContent);

  // Close the browser
  await browser.close();
})();

Please let me know, if any other info is needed. Thanks.

yury-s commented 6 months ago

I cannot reproduce it with the example you provided, so there must be something else. Make sure the framework is running latest playwright (1.41.2 currently). Unfortunately, we cannot act on this without a reproduction.

srajendran123 commented 6 months ago

Hello @yury-s

We just install NodeJs and don’t install playwright explicitly to use BrowserLibrary in our test automation framework.

Yury/Tato – Any advice on how to proceed with https://github.com/MarketSquare/robotframework-browser/issues/3383 and https://github.com/microsoft/playwright/issues/29629?

yury-s commented 6 months ago

Yury/Tato – Any advice on how to proceed with https://github.com/MarketSquare/robotframework-browser/issues/3383 and https://github.com/microsoft/playwright/issues/29629?

As I mentioned above we'll need a reproduction example with playwright that we could run locally. The basic example you pasted above works just fine. So I'd assume that it might be a bug in some old version of playwright or something on the way those parameters are passed to playwright, but this is all speculation. I'm closing this bug as we cannot act on it, but feel free to open a new one and attach a playwright example where the problem appears.