Pages

Monday, 8 August 2022

Quick Coding Solutions: libnss3.so on Heroku when using ChomeDriver


What you're trying to achieve:

Deploying a SpringBoot Application to Heroku.

The SpringBoot Application uses Selenium and ChromeDriver, in either Headless or UI Mode.

You're using BoniGarcia's WebDriverManager to configure the ChromeDriver for Selenium.

You deploy to Heroku and then try to run the Application.


Error message:

/app/.cache/selenium/chromedriver/linux64/104.0.5112.79/chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

ERROR 4 --- [io-55072-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.] with root cause

org.openqa.selenium.WebDriverException: Driver server process died prematurely.


Solution:

You need to add the ChromeDriver and Google Chrome BuildPacks to your Heroku Deployment.

You can do this in the Heroku Web UI -> Your App -> Settings -> Build Packs and Add these two URLs:

  • https://github.com/heroku/heroku-buildpack-google-chrome
  • https://github.com/heroku/heroku-buildpack-chromedriver


Heroku CLI:

heroku create --buildpack https://github.com/heroku/heroku-buildpack-chromedriver.git

heroku create --buildpack https://github.com/heroku/heroku-buildpack-google-chrome.git


In your App.json file, for your "Deploy to Heroku" button, you can add these as:

"buildpacks": [
{
  "url": "https://github.com/heroku/heroku-buildpack-chromedriver"
},{
  "url": "https://github.com/heroku/heroku-buildpack-google-chrome"
}
],

 

I hope that this solves you issue,
Luke

No comments:

Post a Comment

Note: only a member of this blog may post a comment.