I am developing a Node.js app, and I use Selenium Webdriver on it for scraping purposes. However, when I deploy on Heroku, Selenium doesn't work. How can I make Selenium work on Heroku?
Asked
Active
Viewed 1.4k times
12
-
Hello man, have you found the solution for this? I'm also using Node on the server and using Angular on frontend, everything works locally but after I deployed it on heroku, selenium doesn't work – Sherwin Ablaña Dapito Sep 20 '18 at 04:10
2 Answers
5
Below is a javaScript sample code using selenium-webdriver npm package with chrome browser.
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
let options = new chrome.Options();
//Below arguments are critical for Heroku deployment
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
driver.get('http://www.google.com');
driver.quit();
Before you are ready to deploy, you would need to add two buildpacks to Heroku.
- Using Heroku buildpacks command:
$ heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-chromedriver
$ heroku buildpacks:add --index 2 https://github.com/heroku/heroku-buildpack-google-chrome
or
- Config in Heroku dashboard:
Settings -> Add buildpacks -> https://github.com/heroku/heroku-buildpack-chromedriver -> Save changes
Settings -> Add buildpacks -> https://github.com/heroku/heroku-buildpack-google-chrome -> Save changes
Angela L.
- 111
- 1
- 3
-
Hi folks, so with this setup is it possible to disable w3c mode? – Harrison Henri Jun 11 '20 at 17:56
3
I was able to get the Selenium Webdriver working on Node/Heroku using PhantomJs as the headless browser. I installed the PhantomJs buildpack to my Heroku app and it just worked. I struggled to get Chrome and Firefox drivers working on Heroku... I wrote a blog with the steps and code I used to get it working:
Alex Viderman
- 55
- 3
-
11Please include the steps and code in your answer. Answers should not rely on external links for the majority of their information. – Stevoisiak May 11 '17 at 20:01
-
1Same could be said about the blog post :) External references have a way of being deleted. – baash05 Sep 24 '18 at 07:41