Chrome Browser Headless problem : Some specific pages are not rendering in Headless mode

偶尔善良 提交于 2021-01-27 18:30:38

问题


I am trying to automate a process using selenium and chrome browser in Python. My browser works correctly for most pages but is unable to render a few pages including chrome://version/. For general automation(without headless) it returns the page and page source correctly, whereas for headless browsing it returns a blank page with page source as below

<html><head></head><body></body></html>

I have tried chrome in the different operating system including OpenSUSE, fedora, and Windows. I have tried many things like: Removing all the initial arguments, Used the browser with headless off. For Reference: If I run this code

from selenium.webdriver import Chrome
from selenium.webdriver import ChromeOptions
options = ChromeOptions()
# to remove all arguments
options.add_experimental_option( 'excludeSwitches', ['disable-hang-monitor', 'disable-prompt-on-repost', 'disable-background-networking', 'disable-sync', 'disable-translate', 'disable-web-resources', 'disable-client-side-phishing-detection', 'disable-component-update', 'disable-default-apps', 'disable-zero-browsers-open-for-tests', '--enable-automation', '--use-mock-keychain', '--user-data-dir', '--enable-blink-features', '--disable-popup-blocking', '--enable-logging --force-fieldtrials=SiteIsolationExtensions/Control', '--enable-logging', '--force-fieldtrials', '--ignore-certificate-errors', '--load-extension', '--log-level', '--no-first-run','--password-store','--remote-debugging-port','--test-type'
]) 
options.add_argument("--headless")
options.add_argument("--no-sandbox")
browser = Chrome(executable_path=driver_path,options=options)
browser.get("chrome://version")
print(browser.page_source)

It returns the same blank page for headless

<html><head></head><body></body></html>

If the chrome is operated without headless option it will work completely fine.

<!doctype html>
<!--
about:version template page
-->
<html id="t" dir="ltr" lang="en">
  <head>
    <meta charset="utf-8">
    <title>About Version</title>
    <link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
    <link rel="stylesheet" href="chrome://version/about_version.css">
......................

来源:https://stackoverflow.com/questions/58091266/chrome-browser-headless-problem-some-specific-pages-are-not-rendering-in-headl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!