Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
EArminjon opened this issue Jan 18, 2020 · 11 comments
Closed

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

EArminjon opened this issue Jan 18, 2020 · 11 comments

Comments

@EArminjon
Copy link

EArminjon commented Jan 18, 2020

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 pyronlaboratory self-assigned this Jan 18, 2020
@pyronlaboratory
Copy link
Owner

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
Copy link
Owner

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.

@pyronlaboratory pyronlaboratory changed the title NodeJs moz:firefoxOptions.binary Node.js moz:firefoxOptions.binary - SessionNotCreatedError Jan 18, 2020
@EArminjon
Copy link
Author

EArminjon commented Jan 18, 2020

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
Copy link
Author

EArminjon commented Jan 18, 2020

It's still working locally but not on Heroku.

My Firefox version : Mozilla Firefox 68.4.1esr 64bits

@pyronlaboratory
Copy link
Owner

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
Copy link
Owner

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

@pyronlaboratory
Copy link
Owner

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
Copy link
Author

EArminjon commented Jan 18, 2020

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

heroku restart --app my-app-name 

Issue still here :'(

@pyronlaboratory
Copy link
Owner

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
Copy link
Author

I got

1. https://github.com/ronnielivingsince1994/heroku-integrated-firefox-geckodriver
2. heroku/nodejs

@pyronlaboratory
Copy link
Owner

pyronlaboratory commented Jan 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants