Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
flimao opened this issue Jun 28, 2024 · 3 comments

Comments

@flimao
Copy link

flimao commented Jun 28, 2024

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/")
  1. Error NS_ERROR_UNEXPECTED

Expected behavior

I expected to see an error message like SEC_ERROR_UNKNOWN_ISSUER:

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
@mxschmitt mxschmitt transferred this issue from microsoft/playwright-python Jun 28, 2024
@pavelfeldman
Copy link
Member

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
Copy link
Author

flimao commented Jun 29, 2024

@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.

@pavelfeldman
Copy link
Member

Yes, I meant True, but it seems like this property is not resolving your issue. I.e. we pass it to Firefox, but it seems like it does not have an effect you intend it to have. I'd suggest that you file an issue that explains what you need instead of chasing this or some other property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants