Search code examples
node.jsfirefoxselenium-webdrivergeckodriverubuntu-19.04

Firefox with geckodriver don't start on Ubuntu Server


I have Ubuntu Server 19.04 64bit. I use the following packages:

  • nodejs v10.16.0
  • Mozilla Firefox 68.0.1

I installed selenium-webdriver ^4.0.0-alpha.4 in my node.js project.

Also I installed geckodriver 0.24.0 with the following algorithm:

sudo wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
tar -xvzf geckodriver-v0.24.0-linux64.tar.gz
chmod +x geckodriver
sudo mv geckodriver /usr/local/bin/

My project has index.js with following code:

const {Builder, By, Key, util} = require("selenium-webdriver");
const firefox = require('selenium-webdriver/firefox');
async function example() {
    let options = await new firefox.Options()
        .headless();
    let driver = await new Builder().forBrowser("firefox").setFirefoxOptions(options).build();
    await driver.get("https://mobile.facebook.com");  
    await driver.close();
}
example();

When I start my script with command sudo node index.js I get following error:

(node:1303) UnhandledPromiseRejectionWarning: WebDriverError: invalid argument: can't kill an exited process
    at Object.throwDecodedError (/var/nodejs/sites/test/node_modules/selenium-webdriver/lib/error.js:550:15)
    at parseHttpResponse (/var/nodejs/sites/test/node_modules/selenium-webdriver/lib/http.js:560:13)
    at Executor.execute (/var/nodejs/sites/test/node_modules/selenium-webdriver/lib/http.js:486:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:1303) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1303) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Error: invalid argument: can't kill an exited process, and I dont't know, how fix this... If you need more information about my situation, please, ask me, I will try to answer.

UPD: I tried last versions of geckodriver and loock at that I get:

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

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

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

0.21.0: WebDriverError: Process unexpectedly closed with status 1

0.20.1: WebDriverError: Process unexpectedly closed with status 1

0.20.0: WebDriverError: Process unexpectedly closed with status 1

...


Solution

  • You need to update your Firefox browser, it can happen because of mismatch between GeckoDriver and the Firefox Browser.

    If that also don't work then use below version of gecko driver, try with 2nd and 3rd last updated version of gecko driver.

    Not recommanded, still it is possible that you need to downgrade your browser and try it latest or try with 2nd and 3rd last updated version of gecko driver. you should try to update the same with latest version afterwards when binary are available for latest firefox version

    It also one of the probability that your geckodriver is not quit and so it is still running behind which suppress new session to open, you can use below article to kill your geckodriver process

    https://www.tecmint.com/find-and-kill-running-processes-pid-in-linux/