2

There are quite a few posts about facebook/php-webdriver successfully downloading files when non-headless, and the same operation failing when headless. I'm looking for a successful implementation of RemoteWebdriver downloading headlessly for this library (facebook/php-webdriver).

The following article suggests that the library does not yet have the flexibility to set a custom command ("Page.setDownloadBehavior"), which may be what's needed for successful headless downloads. But I have not yet seen an example of a working solution in PHP.

https://github.com/facebook/php-webdriver/issues/605

Any working solutions out there? Thank you.

Ben Coffin
  • 483
  • 4
  • 13

1 Answers1

2

A colleague of mine discovered a beautiful workaround to this shortcoming with Chrome/Chromium browser:

We banged our heads against the wall for weeks trying to get --headless to work with downloads. Here is specifically what we did:

  1. Install Xvfb

    sudo apt-get install xvfb

  2. Start a screen session
  3. Start Xvfb process to provide a virtual display

    Xvfb :1 -screen 5 1024x768x8 &

  4. Add DISPLAY to the environment in the screen session

    export DISPLAY=:1.5

  5. Start chromedriver (which will have the DISPLAY in its environment)

    chromedriver &

Now any chromium-browser processes started by chromedriver will inherit DISPLAY and will use the Xvfb virtual display.

Ben Coffin
  • 483
  • 4
  • 13