Skip to content

Instantly share code, notes, and snippets.

@namuan
Created August 26, 2018 18:01
Show Gist options
  • Save namuan/55d0006b3c59dac09207401fc4418929 to your computer and use it in GitHub Desktop.
Save namuan/55d0006b3c59dac09207401fc4418929 to your computer and use it in GitHub Desktop.
Driving Chrome Headless in Docker with Python #chrome #headless #python

Download and run docker image with headless chrome

docker run -d -p 9222:9222 --cap-add=SYS_ADMIN justinribeiro/chrome-headless

That should start up chrome headless on docker-ip:9222

That uses Chrome Remote Dev protocol which is not what selenium implements so we’ll try to use Chromedriver

Unable to find a docker file with a combination of Chrome headless + Latest Chrome driver

from selenium.webdriver.chrome.options import Options
opt = Options()
opt.add_argument("--headless")
opt.add_argument("--disable-gpu")
opt.add_argument("--no-sandbox")
opt.add_argument("--remote-debugging-port=9222")
opt.binary_location = "/usr/bin/google-chrome"
driver = webdriver.Remote(command_executor='http://docker-ip:4444/wd/hub', desired_capabilities=opt.to_capabilities())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment