cyrus-and / chrome-remote-interface

Chrome Debugging Protocol interface for Node.js
MIT License
4.27k stars 306 forks source link

Blank screenshots when using --headless and --proxy-server at the same time. #204

Closed lucasefe closed 7 years ago

lucasefe commented 7 years ago

If I use chrome without the --headless option, everything works, which means traffic goes through the selected proxy, and when I capture the screens, the resulting images look the way I expect them to.

If I add --headless to the command line arguments, I start capturing blank screens.

I tried both Canary and Chromium.

Is there anything I can do figure out what's going on? I added logging to the proxy, and I see only one connection happening, instead of several, which is what I see when "it works".

Let me know if there's something I can do. Thanks in advance.

Related issue: https://github.com/cyrus-and/chrome-remote-interface/issues/175

(I opened this one because the related one was already closed)

cyrus-and commented 7 years ago

This is hardly a problem with this project, you should file and issue here.

Moreover, I cannot even start Chrome if I set both --headless and --proxy-server at the same time on Linux:

$ google-chrome --proxy-server=socks5://127.0.0.1:9050 --remote-debugging-port=9222 --headless
[0718/200052.562414:ERROR:headless_shell.cc(551)] Malformed proxy server url
lucasefe commented 7 years ago

I'm using a normal HTTP proxy, not a socks5.

And you are right, this is not a problem related to chrome-remote-interface.

Just to clarify, here's how to reproduce it:

I run a proxy server in port 4001, simply by executing this file with nodejs. Any other proxy would suffice as well.

Run chrome, headless, with proxy:

On Mac: /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --headless --disable-gpu --remote-debugging-port=9222 --proxy-server=localhost:4001 https://www.chromestatus.com

On your normal chrome, browse localhost:9222, follow the steps, and you'll see the blank screen.

If you do the same without the --headless option, the screen will show the actual content of the browsed page.

As we can see, I did not use chrome-remote-interface, so it's not related to it.

Thanks, and sorry for the inconvenience.

cyrus-and commented 7 years ago

If you decide to file an issue upstream of if you find more info, feel free to post it here if you want, so to help future visitors. Thanks.

nhoellinger commented 7 years ago

Hi! Are there any new updates? Because I'm facing the same problem. I'm using the BrowserMobProxy. It would even be helpful to know if that is a bug or not...

cyrus-and commented 7 years ago

@nhoellinger I don't think an upstream issue has been filed, you can do that. You may also want to ask this in the Google Group.

mitaltia commented 6 years ago

I am also facing the same issue as @lucasefe posted here. @lucasefe Are you able to resolve the blank page issue with headless chrome? Thnkas!

chandnarahul commented 6 years ago

i am facing the same issue, as advised above i have raise it here : https://groups.google.com/forum/#!topic/chrome-debugging-protocol/VcF5Abm1IeE

xyproto commented 6 years ago

Not sure if it's related, but unset TZ before running headless chrome solved the issue with blank screenshots here. When TZ was set (correctly) to /usr/share/zoneinfo/Europe/Oslo, there were errors in the js console in chrome.

anarang commented 4 years ago

I am also facing the same issue with chromedriver, is there a resolution to it yet?

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--proxy-server=%s' % proxy_url)

 driver = webdriver.Chrome(ChromeDriverManager(path=os.environ['PYTHONPATH']).install(), chrome_options=options)

When I remove the --proxy-server, headless chrome works fine but otherwise it would show a blank screen. I am using this with Selnium python. I am trying to run the selenium tests inside fedora 32 docker container using selenium. $ google-chrome --version Google Chrome 84.0.4147.105

Any solution to this will be appreciated.

0xhexdec commented 3 years ago

For me, adding the --ignore-certificate-errors did the trick.

options = Options()
options.add_argument('headless')
options.add_argument('ignore-certificate-errors')
options.add_argument('--proxy-server=%s' % proxy_url)

driver = RemoteDriver(hubUrl, options=options)

Done with selenium python I run the tests in Selenium Grid (3) with Windows and Linux nodes.

hope this helps

yotamgod commented 3 years ago

@0xhexdec Saved me

fortuneteller commented 3 years ago

:tada: @0xhexdec

eostis commented 3 years ago

@0xhexdec Saved me too!

With phpunit selenium:

$capabilities = [ 'chromeOptions' => [ 'w3c' => false, ], ];

// Headless
$capabilities['chromeOptions']['args'] = [
  '--headless',
  '--ignore-certificate-errors', // prevents blank screenshots
];

$this->setDesiredCapabilities( $capabilities );