GithubHelp home page GithubHelp logo

cordery / heroku-buildpack-headless-chrome Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7 KB

Get headless chrome working on heroku

Shell 100.00%
heroku heroku-buildpack selenium chrome chromedriver xvfb

heroku-buildpack-headless-chrome's Introduction

heroku-buildpack-headless-chrome

To have headless chrome work correctly on Heroku, particularly for use with Heroku CI, you need to have both Chromium & Chromedriver installed, as well as Xvfb or you will see errors every time you try to send keys. In order to have a fully functional headless chrome install ready to use with for example Selenium, you just need to add heroku-buildpack-apt and this buildpack to your environment.test.buildpacks config.

This buildpack:

  1. patches Xvfb to work correctly given the location of the heroku-buildpack-apt installed files (/app/.apt/usr/bin).
  2. creates a shim for chrome which adds the --headless --no-sandbox --disable-gpu flags by default.
  3. installs the latest version of Chromedriver

Note: This buildpack is a replacement for heroku-buildpack-google-chrome

Usage

Aptfile

Create or amend a file called Aptfile in your project root with the following content:

xvfb libxss1 xfonts-100dpi xfonts-75dpi xfonts-cyrillic xorg dbus-x11
https://dl.google.com/linux/direct/google-chrome-beta_current_amd64.deb

app.json

Your app.json should list the buildpacks in this order:

{
    "environments": {
        "test": {
            "buildpacks": [
                {"url": "https://github.com/heroku/heroku-buildpack-apt"},
                {"url": "https://github.com/cordery/heroku-buildpack-headless-chrome"},
                ... # rest of your buildpacks here
            }
        }
    }
}

Framework Notes

Django

Django's LiveServerTestCase does not require any modifications to work. Adapt to your own pages and use as is.

However, Django's default test runner "DiscoverRunner" cannot run tests on Heroku CI with Heroku Postgres because it requires createdb and dropdb permissions which Heroku does not provide. In order to resolve this you must override the class to disable the createdb/dropdb behavior. An example of this for Postgres can be found in this gist.

Troubleshooting

I keep getting the following error: an X display is required for keycode conversions, consider using Xvf

Xvfb is not properly installed. If this buildpack is correctly installed you will see "Patching Xvfb" during the build process.

If you see that "Patching Xvfb" and are still getting the above error then most likely another buildpack is reinstalling apt-get debs into the ./.apt/usr/bin dir and overwriting the changes made by this buildpack to Xvfb.

For example, including heroku-buildpack-google-chrome alongside heroku-buildpack-apt will cause this.

If you need both buildpacks and cannot resolve this behavior by eliminating the non-heroku-buildpack-apt pack, then just make sure this buildpack (heroku-buildpack-headless-chrome) comes after every other buildpack.

Attribution

Inspired or derived from:

  1. https://github.com/heroku/heroku-buildpack-google-chrome
  2. https://github.com/captain401/heroku-buildpack-xvfb

License

MIT

heroku-buildpack-headless-chrome's People

Contributors

cordery avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.