How to use selenium nodeJS on glitch.com

This thread will be helpful for every person which want to know how to use selenium with a chrome driver specially.

I still didn’t find how to use selenium, I don’t know how making it work with chromedriver.
Can someone put some specific code please and give me accurate explanations about how to install chrome and all those things … :sob:
I always have this error

(node:558) UnhandledPromiseRejectionWarning: WebDriverError: unknown error: cannot find Chrome binary
(Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Linux 4.4.0-1066-aws x86_64)

when i use this code

require('chromedriver');
const {Builder, By, Key, logging, until} = require('selenium-webdriver');
let driver = await new Builder()
      .forBrowser('chrome')
      .build();

and i got this error

  (unknown error: DevToolsActivePort file doesn't exist)

  (The process started from chrome location /rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/chromedriver/73.0.0/node_modules/chromedriver/lib/chromedriver/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

  (Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Linux 4.4.0-1066-aws x86_64)

    at Object.checkLegacyResponse (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/error.js:546:15)

    at parseHttpResponse (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/http.js:509:13)

    at doSend.then.response (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/http.js:441:30)

    at <anonymous>

    at process._tickCallback (internal/process/next_tick.js:189:7)

From: Task: WebDriver.createSession()

    at Function.createSession (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/lib/webdriver.js:769:24)

    at Function.createSession (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/chrome.js:761:15)

    at createDriver (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/index.js:170:33)

    at Builder.build (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/selenium-webdriver/3.6.0/node_modules/selenium-webdriver/index.js:642:16)

at create (/app/server.js:21:8)

at /app/server.js:57:5

    at Layer.handle [as handle_request] (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/express/4.16.4/node_modules/express/lib/router/layer.js:95:5)

    at next (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/express/4.16.4/node_modules/express/lib/router/route.js:137:13)

    at Route.dispatch (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/express/4.16.4/node_modules/express/lib/router/route.js:112:3)

    at Layer.handle [as handle_request] (/rbd/pnpm-volume/3413e97b-1507-420a-aacc-b09a3a8055ce/node_modules/.registry.npmjs.org/express/4.16.4/node_modules/express/lib/router/layer.js:95:5)

(node:4272) 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:4272) [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.

when i use this code

require('chromedriver');
const {Builder, By, Key, logging, until} = require('selenium-webdriver');
let driver = await new Builder()
      .withCapabilities({'browserName':'chrome', "chromeOptions":{binary: require('chromedriver').path}})
      .build();

Hey @AimvenDragtow, I think these errors are indicative of the fact that the chrome drivers aren’t installed in the Glitch project container. I played with the briefly a little while ago myself and wasn’t able to install those because they’re far too large for the container’s available space. I don’t know of anyone who’s gotten Selenium working in Glitch, but I think folks have had a little more luck with puppeteer.

1 Like

ok thanks it worked for me
puppeteer-sample
this is an example that i found for anyone who want to use it

1 Like