Search code examples
ruby-on-railsselenium-webdriverherokufirefox

Get Firefox working on Heroku app: XPCOMGlueLoad error


I am trying to get Firefox working on Heroku. My recent build succeeded but some problems:

  1. 'Application error' when trying to access the app's URL ('check your logs at heroku logs --tail').

  2. heroku logs --tail error:

    2021-05-07T02:37:38.937508+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=www.mysite.com request_id=be150e6e-295d-4121-a90a-gh8519sa174 fwd="<ipaddress>" dyno= connect= service= status=503 bytes= protocol=http
    2021-05-07T02:37:39.405719+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=www.mysite.com request_id=6caff434-1hfa-4gqb-a3c3-7209sh2k0cf9 fwd="<ipaddress>" dyno= connect= service= status=503 bytes= protocol=http

  3. The typical solution for the above H14 error is to scale the dynos up:

    ➜ myapp git:(master) ✗ heroku ps:scale web=1
    Scaling dynos... !
    ▸ Couldn't find that process type (web).

  4. heroku console error:

    XPCOMGlueLoad error for file /app/vendor/firefox/libmozgtk.so:
    libgtk-3.so.0: cannot open shared object file: No such file or directory.
    Couldn't load XPCOM.

The heroku push looked like:

➜  myapp git:(master) ✗ git push heroku master                                           
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 349 bytes | 349.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: http://github.com/buitron/firefox-buildpack
remote: -----> firefox app detected
remote: -----> Extracting Firefox binaries to /tmp/build_1f06c3e2/vendor/firefox
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console
remote: 
remote: -----> Compressing...
remote:        Done: 81.7M
remote: -----> Launching...
remote:        Released v21
remote:        https://myapp.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/myapp.git

I have tried the following buildpacks so far with NO changes in result:

  1. heroku-integrated-firefox-geckodriver
  2. buitron's firefox-buildpack

My app only needs this code in one place. Here is that code:

require 'webdrivers/geckodriver'
require 'selenium-webdriver'
require 'fileutils'
Selenium::WebDriver.logger.level = :info

# SET UP SELENIUM
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = download_dir
profile['browser.helperApps.neverAsk.saveToDisk'] = ('application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, text/csv')
options = Selenium::WebDriver::Firefox::Options.new(profile: profile, args: ['-headless'])
driver = Selenium::WebDriver.for :firefox, options: options

driver.manage.timeouts.implicit_wait = 10 # seconds
wait = Selenium::WebDriver::Wait.new(:timeout => 15)

driver.get "https://theurl.com"

...traverse website...
driver.quit

Solution

  • The buitron buildpack has some issues, including a long-running unfixed bug due to a missing semi-colon.

    The current recommendation is to use evosystem-jp's buildpack. I got it working by cloning the buildpack and updating to the latest versions of Firefox and Geckodriver.