OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Playwright Python: NS_ERROR_UNKNOWN when launching Firefox with firefox_user_prefs and security.enterprise_roots.enabled

  • Thread starter Thread starter LmnICE
  • Start date Start date
L

LmnICE

Guest
I'm trying to use playwright in Python to scrape a portal in my company internal network, and I'm getting a useless error message (NS_ERROR_UNKNOWN) when I try to set some preferences in Firefox (according to playwrights documentation)

I'm using Ubuntu 22.04.4 LTS with WSL and Python 3.10.12. The portal only works properly in Firefox, and is only served through HTTPS. The company MITMs all SSL connections (including connections to the internal network), but I have the company root CA installed in WSL.

Here's a sample code:

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 untrusted certificate for testing purposes
    page = browser.new_page().goto("https://untrusted-root.badssl.com/")

When I run this code, I get the following error message:

Code:
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]

If I run the same code without the firefox_user_prefs setting, I get the following error mesage:

Code:
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"

I get the same error message as immediately above (SEC_ERROR_UNKOWN_ISSUER) if I run the code with some other random Firefox setting, say:

Code:
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/")

The error appears to stem from the specific setting security.enterprise_roots.enabled, but other than that I'm stymied.

I would greatly appreciate it if someone would help me getting the playwright version of Firefox to work with custom CAs.
<p>I'm trying to use <code>playwright</code> in Python to scrape a portal in my company internal network, and I'm getting a useless error message (<code>NS_ERROR_UNKNOWN</code>) when I try to set some preferences in Firefox (according to <code>playwright</code>s <a href="https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch" rel="nofollow noreferrer">documentation</a>)</p>
<p>I'm using Ubuntu 22.04.4 LTS with WSL and Python 3.10.12. The portal only works properly in Firefox, and is only served through HTTPS. The company MITMs all SSL connections (including connections to the internal network), but I have the company root CA installed in WSL.</p>
<p>Here's a sample code:</p>
<pre class="lang-py prettyprint-override"><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 untrusted certificate for testing purposes
page = browser.new_page().goto("https://untrusted-root.badssl.com/")
</code></pre>
<p>When I run this code, I get the following error message:</p>
<pre><code>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]
</code></pre>
<p>If I run the same code without the <code>firefox_user_prefs</code> setting, I get the following error mesage:</p>
<pre><code>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"
</code></pre>
<p>I get the same error message as immediately above (<code>SEC_ERROR_UNKOWN_ISSUER</code>) if I run the code with some other random Firefox setting, say:</p>
<pre class="lang-py prettyprint-override"><code>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/")
</code></pre>
<p>The error appears to stem from the specific setting <code>security.enterprise_roots.enabled</code>, but other than that I'm stymied.</p>
<p>I would greatly appreciate it if someone would help me getting the <code>playwright</code> version of Firefox to work with custom CAs.</p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top