8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

Playwright Python:使用 firefox_user_prefs 和 security.enterprise_roots.enabled 启动 Firefox 时出现 NS_ERROR_UNKNOWN

dr_barto 2月前

14 0

我正在尝试使用 Python 中的 playwright 来抓取我公司内部网络中的门户,当我尝试在 Firefox 中设置一些首选项时,我收到了一条无用的错误消息(NS_ERROR_UNKNOWN)(

我正在尝试使用 playwright Python 来抓取我公司内部网络中的门户, NS_ERROR_UNKNOWN 当我尝试在 Firefox 中设置一些首选项时,我收到了一条无用的错误消息(根据 playwright s 文档 这篇 关于在 Firefox 中设置自定义 CA 的 Mozilla 知识库文章)

我使用的是 Ubuntu 22.04.4 LTS,带有 WSL 和 Python 3.10.12。该门户仅在 Firefox 中正常运行,并且仅通过 HTTPS 提供服务。公司 MITM 所有 SSL 连接(包括与内部网络的连接),但我已在 WSL 中安装了公司根 CA。

以下是示例代码:

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

当我运行此代码时,出现以下错误消息:

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]

如果我运行相同的代码但没有 firefox_user_prefs 设置,我会收到以下错误消息:

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"

如果我使用其他随机 Firefox 设置运行代码, SEC_ERROR_UNKOWN_ISSUER 我会收到与上面相同的错误消息(

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

该错误似乎源于特定的设置 security.enterprise_roots.enabled ,但除此之外我感到很困惑。

可以与自定义 CA 兼容的 Firefox 版本, playwright 我将不胜感激。

帖子版权声明 1、本帖标题:Playwright Python:使用 firefox_user_prefs 和 security.enterprise_roots.enabled 启动 Firefox 时出现 NS_ERROR_UNKNOWN
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由dr_barto在本站《ubuntu》版块原创发布, 转载请注明出处!
最新回复 (0)
返回
作者最近主题: