让 Firefox 在 Heroku 应用程序上运行:XPCOMGlueLoad 错误

Get Firefox working on Heroku app: XPCOMGlueLoad error

我正在尝试让 Firefox 在 Heroku 上运行。我最近的构建成功了,但出现了一些问题:

  1. 'Application error' 尝试访问应用程序的 URL ('check your logs at heroku logs --tail').

  2. heroku logs --tail 错误:

    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. 上述H14错误的典型解决方案是放大dynos:

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

  4. heroku console 错误:

    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.

heroku 推送看起来像:

➜  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

到目前为止,我已经尝试了以下构建包,结果没有任何变化:

  1. heroku-integrated-firefox-geckodriver
  2. buitron 的 firefox-buildpack

我的应用程序只需要在一个地方使用此代码。这是代码:

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

buitron buildpack 存在一些问题,包括一个长期 运行 由于缺少分号而未修复的错误。

目前推荐使用evosystem-jp's buildpack。我通过克隆构建包并更新到最新版本的 Firefox 和 Geckodriver 来让它工作。