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
63.66k stars 3.44k forks source link

[Bug]: NS_ERROR_UNEXPECTED when launching Firefox with firefox_user_prefs and security.enterprise_roots.enabled in Ubuntu WSL #31485

Open flimao opened 2 days ago

flimao commented 2 days ago

Version

1.44.0

Steps to reproduce

  1. Start fresh environment
  2. pip install playwright
  3. playwright install firefox
  4. Run this code:
    
    from playwright.sync_api import sync_playwright

with sync_playwright() as pwobj: browser = pwobj.firefox.launch( headless = False, firefox_user_prefs = { "security.enterprise_roots.enabled": "true" } )

# page with broken certificate for testing purposes
page = browser.new_page().goto("https://untrusted-root.badssl.com/")
5. Error `NS_ERROR_UNEXPECTED`

### Expected behavior

I expected to see an error message like `SEC_ERROR_UNKNOWN_ISSUER`:
```console

Traceback (most recent call last):
  File "/home/lmnice/sw/projects/mapebot/Rascunhos/playwright_error.py", line 15, in <module>
    page = browser.new_page().goto("https://untrusted-root.badssl.com/")
  File "/home/lmnice/.venvs/error_playwright/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 8686, in goto
    self._sync(
  File "/home/lmnice/.venvs/error_playwright/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
  File "/home/lmnice/.venvs/error_playwright/lib/python3.10/site-packages/playwright/_impl/_page.py", line 519, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "/home/lmnice/.venvs/error_playwright/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 145, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "/home/lmnice/.venvs/error_playwright/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 59, in send
    return await self._connection.wrap_api_call(
  File "/home/lmnice/.venvs/error_playwright/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 514, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: Page.goto: SEC_ERROR_UNKNOWN_ISSUER
Call log:
navigating to "https://untrusted-root.badssl.com/", waiting until "load"

Actual behavior

I get an unhelpful error message NS_ERROR_UNEXPECTED:

Traceback (most recent call last):
  File "/home/lmnice/sw/projects/mapebot/Rascunhos/playwright_error.py", line 4, in <module>
    browser = pwobj.firefox.launch(
  File "/home/lmnice/.venvs/mapebot/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 13991, in launch
    self._sync(
  File "/home/lmnice/.venvs/mapebot/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
  File "/home/lmnice/.venvs/mapebot/lib/python3.10/site-packages/playwright/_impl/_browser_type.py", line 94, in launch
    Browser, from_channel(await self._channel.send("launch", params))
  File "/home/lmnice/.venvs/mapebot/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 59, in send
    return await self._connection.wrap_api_call(
  File "/home/lmnice/.venvs/mapebot/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 514, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: BrowserType.launch: Protocol error (Browser.enable): Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.setStringPref]
Call log:
<launching> /home/lmnice/.cache/ms-playwright/firefox-1449/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-XXXXXXFpc6uf -juggler-pipe -silent
  - <launched> pid=24470
  - [pid=24470][err] JavaScript warning: resource://services-settings/Utils.sys.mjs, line 114: unreachable code after return statement
  - [pid=24470][out] console.warn: services.settings: Ignoring preference override of remote settings server
  - [pid=24470][out] console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
  - [pid=24470][out] console.error: ({})
  - [pid=24470][out] 
  - [pid=24470][out] Juggler listening to the pipe
  - [pid=24470][out] console.error: "Warning: unrecognized command line flag" "-wait-for-browser"
  - [pid=24470][out] 
  - [pid=24470][out]         ERROR: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.setStringPref] Browser.enable@chrome://juggler/content/protocol/BrowserHandler.js:40:24
  - [pid=24470][out]

Additional context

I'm trying to scrape one of my company's internal web portal. The portal only works properly in Firefox and is only served through HTTPS. The company MITM's all SSL connections. I have the company's root CA installed in WSL.

If I remove the firefox_user_prefs argument, or if I set any other option in firefox_user_prefs, like so:

from playwright.sync_api import sync_playwright

with sync_playwright() as pwobj:
    browser = pwobj.firefox.launch(
        headless = False,
        firefox_user_prefs = {
            # random option just to check if other options also cause this error
            "browser.backspace_action": 0
        }
    )

    # page with broken certificate for testing purposes
    page = browser.new_page().goto("https://untrusted-root.badssl.com/")

I get the SEC_ERROR_UNKNOWN_ISSUER as expected.

I asked for help regarding this issue in StackOverflow. So for it has 20 views, but no comments or answers.

Environment

- Operating System: Ubuntu 22.04.4 LTS in WSL (Windows 10, WSL 2.2.4.0)
- CPU: Intel Core i7-12800H
- Browser: Firefox
- Python Version: 3.10.12
- Other info: Python env only has playwright installed
pavelfeldman commented 2 days ago

Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPrefBranch.setStringPref]

"security.enterprise_roots.enabled": "true"

I guess it should be boolean rather than a string?

"security.enterprise_roots.enabled": true

flimao commented 1 day ago

@pavelfeldman, if I set the option exactly as you wrote it, Python throws a NameError:

(...)
NameError: name 'true' is not defined. Did you mean: 'True'?

If I write it as a Python boolean instead ("security.enterprise_roots.enabled": True), playwright throws the SEC_ERROR_UNKNOWN_ISSUER error, apparently ignoring the Firefox setting.