
我正在嘗試使用 Firefox 的命令列介面截取螢幕截圖。我確保新設定檔的名稱與所有其他現有設定檔不同。最後一個命令運行,但永遠不會終止,也不會產生螢幕截圖。
$ firefox --version
> Mozilla Firefox 66.0.3
$ firefox -CreateProfile unique-profile-name
> *** You are running in headless mode.
$ firefox -P unique-profile-name -headless --screenshot https://developer.mozilla.com/en-US/
> *** You are running in headless mode.
如何使用命令列介面並firefox
建立頁面的螢幕截圖?
我收到了“截圖”命令https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode。
我也嘗試過指定視窗大小--window-size=800,1000
並確保 URL 不會重定向。
答案1
給定的 url 似乎存在憑證錯誤,憑證對於請求的網域無效,這可能是 firefox 螢幕截圖在此範例中不起作用的原因。試試以下任一方法:
- 接受該憑證作為 Firefox 中的例外並重新運行 headless firefox(它不應再掛起)。如果必須使用命令列,這可能有幫助。
或者
- 如果 Firefox 不是必需的,請嘗試使用 chromium
--ignore-certificate-errors
:
chromium --headless --screenshot=output.jpg --ignore-certificate-errors https://developer.mozilla.com/en-US
PS:
-headless
使用時隱含firefox --screenshot