6

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">
......................
Mayank
  • 1,364
  • 1
  • 15
  • 29
  • 3
    @DebanjanB the duplicate question does have nothing in common with this question. – AndiCover Sep 24 '19 at 09:20
  • @AndiCover Observe the error `(unknown error: DevToolsActivePort file doesn't exist)` in the [initial version of the question](https://stackoverflow.com/revisions/58076086/1) before OP edited it. – undetected Selenium Sep 24 '19 at 09:24
  • 1
    @DebanjanB The error is what I tried and mentioned as an approach, just in case. This has got nothing to do with the original question and is completely unrelated to the problem statement. Please consider removing the duplicate tag. – Mayank Sep 24 '19 at 09:28
  • @Mayank Before _...got nothing to do with the original question..._ and _...original question and is completely unrelated..._, did you get a chance to look at the dup marked discussion atleast for once? – undetected Selenium Sep 24 '19 at 09:32
  • 1
    @DebanjanB I did and I had gone through this even before posting this question. My question is that "a few pages cannot be loaded correctly and return blank page" duplicate against the question "Unable to start browser.". Please understand the question and its use case and consider giving a possible solution if possible. – Mayank Sep 24 '19 at 09:42
  • @DebanjanB I am stuck on this genuine problem, which I am unable to find any resource or solution or assistance to. You should understand the unintended consequences of your actions. – Mayank Sep 24 '19 at 10:26
  • 1
    You can flag the question to get moderator attention. If that does not help I would suggest to delete the question and ask it again. – AndiCover Sep 24 '19 at 11:07
  • @AndiCover Thanks!. I did that. – Mayank Sep 24 '19 at 11:39

2 Answers2

1

I guess that selenium is starting browser in headless and, because it's getting chrome://version from local files, it just can't render it.

I think that the same will happen with all chrome:// (and local files as .pdf or something) if running in headless.

Try opening some pdf file in chrome browser and then: driver.get(<path_to_pdf>) both headless and normal

Misieq
  • 507
  • 2
  • 12
  • I have tested your hypothesis and driver.get() works both for headless and without headless. – Mayank Sep 24 '19 at 08:57
0

try these Options:

options.addArguments("disable-blink-features=AutomationControlled");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
partinis
  • 139
  • 12