pyronlaboratory / heroku-integrated-firefox-geckodriver

Buildpack enables your client code to access Firefox along with Geckodriver in a Heroku slug.
https://pyronlaboratory.github.io/heroku-integrated-firefox-geckodriver/
MIT License
41 stars 80 forks source link

Node.js moz:firefoxOptions.binary - SessionNotCreatedError #3

Closed EArminjon closed 4 years ago

EArminjon commented 4 years ago

Hello,

I created a nodejs project which use selenium with firefox headless. My project works locally but not on heroku.

SessionNotCreatedError: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
const {Builder, By, until} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

const screen = {
  width: 1920,
  height: 1080
};

let options = new firefox.Options();
//Below arguments are critical for Heroku deployment
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.windowSize(screen);

let driver = new Builder()
  .forBrowser('firefox')
  .setFirefoxOptions(options)
  .build();

Sans titre

My package.json

{
  "name": "untitled",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "latest",
    "selenium-webdriver": "latest",
    "geckodriver": "^1.19.1"
  },
  "engines": {
    "node": "13.6.0"
  }
}
pyronlaboratory commented 4 years ago

Probable reason for this error - missing configurations while creating the driver object.

You need to add to add a binary attribute, something like this const binary = new firefox.Binary(); and pass the FIREFOX_BIN path as a parameter to it.

And call Builder() as follows

const driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(new firefox.Options().setBinary(binary))
.build();

This should clear your SessionNotCreatedError error

pyronlaboratory commented 4 years ago

Also, since you're running firefox with '--headless' attribute, you might want to consider adding '--remote-debugging-port=9224' attribute as well.

options.addArguments('--remote-debugging-port=9224');

This will enable remote debugging on a different port, if you're on the same network. As well as, you should set driver's debugging option to trace level.

EArminjon commented 4 years ago

I can't do const binary = new firefox.Binary() :

TypeError: firefox.Binary is not a constructor

I search a new solution on google but i got a new error :

2020-01-18T18:10:02.201708+00:00 app[web.1]: WebDriverError: invalid argument: can't kill an exited process
2020-01-18T18:10:02.201720+00:00 app[web.1]: at Object.throwDecodedError (/app/node_modules/selenium-webdriver/lib/error.js:550:15)
2020-01-18T18:10:02.201721+00:00 app[web.1]: at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:563:13)
2020-01-18T18:10:02.201723+00:00 app[web.1]: at Executor.execute (/app/node_modules/selenium-webdriver/lib/http.js:489:26)
2020-01-18T18:10:02.201725+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5) {
2020-01-18T18:10:02.201728+00:00 app[web.1]: name: 'WebDriverError',
2020-01-18T18:10:02.201729+00:00 app[web.1]: remoteStacktrace: ''
2020-01-18T18:10:02.201732+00:00 app[web.1]: }

My option code :

const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
require('geckodriver');

const screen = {
  width: 1920,
  height: 1080
};

let options = new firefox.Options();
//Below arguments are critical for Heroku deployment
options.setBinary(process.env.FIREFOX_BIN);
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments('--remote-debugging-port=9224');
options.windowSize(screen);

let driver = new Builder()
  .forBrowser('firefox')
  .setFirefoxOptions(options)
  .build();
EArminjon commented 4 years ago

It's still working locally but not on Heroku.

My Firefox version : Mozilla Firefox 68.4.1esr 64bits

pyronlaboratory commented 4 years ago

WebDriverError: invalid argument: can't kill an exited process

This is a popular selenium webdriver error suggesting that a previous session is still running and has not yet been terminated. As a result a new instance is not able to spawn.

pyronlaboratory commented 4 years ago

Reboot your heroku instance, it should probably resolve the issue now.

pyronlaboratory commented 4 years ago

I can't do const binary = new firefox.Binary() :

TypeError: firefox.Binary is not a constructor

I search a new solution on google but i got a new error :

2020-01-18T18:10:02.201708+00:00 app[web.1]: WebDriverError: invalid argument: can't kill an exited process
2020-01-18T18:10:02.201720+00:00 app[web.1]: at Object.throwDecodedError (/app/node_modules/selenium-webdriver/lib/error.js:550:15)
2020-01-18T18:10:02.201721+00:00 app[web.1]: at parseHttpResponse (/app/node_modules/selenium-webdriver/lib/http.js:563:13)
2020-01-18T18:10:02.201723+00:00 app[web.1]: at Executor.execute (/app/node_modules/selenium-webdriver/lib/http.js:489:26)
2020-01-18T18:10:02.201725+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5) {
2020-01-18T18:10:02.201728+00:00 app[web.1]: name: 'WebDriverError',
2020-01-18T18:10:02.201729+00:00 app[web.1]: remoteStacktrace: ''
2020-01-18T18:10:02.201732+00:00 app[web.1]: }

My option code :

const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
require('geckodriver');

const screen = {
  width: 1920,
  height: 1080
};

let options = new firefox.Options();
//Below arguments are critical for Heroku deployment
options.setBinary(process.env.FIREFOX_BIN);
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments('--remote-debugging-port=9224');
options.windowSize(screen);

let driver = new Builder()
  .forBrowser('firefox')
  .setFirefoxOptions(options)
  .build();

options.setBinary( ) works just fine.

EArminjon commented 4 years ago

Reboot your heroku instance, it should probably resolve the issue now.

heroku restart --app my-app-name 

Issue still here :'(

pyronlaboratory commented 4 years ago

Can you share the result from heroku buildpacks -a your-app-name.

Also if you want real time support you can ping me on discord Ronnie#4190

EArminjon commented 4 years ago

I got

1. https://github.com/ronnielivingsince1994/heroku-integrated-firefox-geckodriver
2. heroku/nodejs
pyronlaboratory commented 4 years ago

Forget about that, I saw your dashboard screenshot. Thanks for uploading it. Helped in investigating..

Remove the buildpack and install again from cli

heroku buildpacks:add https://github.com/pyronlaboratory/heroku-integrated-firefox-geckodriver.git

This should probably fix it for you mate