Docker — WebDriverError: неизвестная ошибка: Chrome не удалось запустить: ненормально вышел — JavaScript — ChromeDriver

#node.js #docker #selenium-chromedriver #containers

Вопрос:

Вот мой файл docker.

 FROM node:17.2.0  USER root  WORKDIR /LT  RUN apt-get update   RUN apt-get install git --yes  COPY /LT . COPY /LT/test . COPY ["/LT/package.json", "."]  # Install Google Chrome RUN apt-get install wget RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb RUN apt-get install ./google-chrome*.deb --yes  ENV CHROME_BIN=/usr/bin/google-chrome  RUN npm install RUN npm ci RUN npm install nodejs RUN npm install mocha -g RUN npm install chromedriver -g --unsafe-perm RUN npm install selenium-webdriver RUN npm install webdriver-manager #RUN webdriver-manager update CMD ["node", "./test/script1.js"]  

Ниже приведен мой файл javascript nodejs, который использует chrome для запуска приложения и входа в систему.

 require("chromedriver"); const {By,Key,Builder} = require("selenium-webdriver"); const chrome = require('selenium-webdriver/chrome');    async function getAuthCode(){    const url = "https://abcd.com";    //To wait for browser to build and launch properly  let driver = await new Builder()  .forBrowser("chrome")  .setChromeOptions(new chrome.Options().headless())     //.setChromeOptions(new chrome.Options().addArguments(['--no-sandbox','-headless', '--disable-dev-shm-usage']))     .build();    await driver.get(url);  console.log(driver);  const wait = ms =gt; new Promise(resolve =gt; setTimeout(resolve, ms));  await wait(1 * 20 * 1000);  await driver.manage().window().setRect({ width: 1552, height: 840 });  await driver.findElement(By.id("emailInput")).click();  await driver.findElement(By.id("emailInput")).sendKeys("vendor-OSDU@slb.com");    await driver.findElement(By.id("submitbutton")).click();        await wait(1 * 20 * 1000);      await driver.quit();    return 'some data';  }   async function testAuthCode() {  var cCode = await getAuthCode();  console.log(cCode); } testAuthCode();  

Когда я запускаю свой файл docker compose, используя тот же файл docker, который указан выше, я получаю следующую ошибку.

 WebDriverError: unknown error: Chrome failed to start: exited abnormally. -nodejs-1 | (unknown error: DevToolsActivePort file doesn't exist) -nodejs-1 | (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) -nodejs-1 | at Object.throwDecodedError (/LT/node_modules/selenium-webdriver/lib/error.js:539:15)  

I know the reason , It can not find the chromedriver at the default path ‘/usr/bin/google-chrome’.

Either

  1. I have to install chrome at the default location given Or
  2. give the path of that location where chrome is actually installed.

In either case, How do I do it in JavaScript or docker?

PS: The script runs perfectly fine in my local windows environment. I already went through similar issues posted here but most of the solutions are python specific and my knowledge of docker is limited.