banner
libxcnya.so

libxcnya.so

Nothing...
telegram
twitter
github
email

Deploying Node.JS + Selenium project in Linux environment - Pitfalls and Solutions

Preface#

Because the blogger's Windows server is about to expire, so the things that were previously running on the Windows machine need to be considered for migration to Linux. Then I tried to run the Shit Code written in the second grade of elementary school and found that it couldn't run. And that's why we have this water article today.

Installation#

Install Google Chrome

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install ./google-chrome-stable_current_amd64.deb -y
rm google-chrome-stable_current_amd64.deb

(To be honest, this address is not blocked in China)

Enter google-chrome --version to verify if the installation is successful.

1

If the version is output normally, it means the installation is successful.

In NPM, execute npm install selenium-webdriver should theoretically configure the chromedriver for use in node projects. Let's take the example of the small tool I wrote last month to boost the score on Hostloc during the defense.

At that time, after everything was installed, I encountered an error when I ran it.

2

root@NekoServer:~# node main.js

=.=

An error occurred: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
/root/node_modules/selenium-webdriver/lib/error.js:524
    let err = new ctor(data.message)
              ^

SessionNotCreatedError: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    at Object.throwDecodedError (/root/node_modules/selenium-webdriver/lib/error.js:524:15)
    at parseHttpResponse (/root/node_modules/selenium-webdriver/lib/http.js:601:13)
    at Executor.execute (/root/node_modules/selenium-webdriver/lib/http.js:529:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  remoteStacktrace: '#0 0x5611b9842f83 <unknown>\n' +
    '#1 0x5611b94fbcf7 <unknown>\n' +
    '#2 0x5611b953360e <unknown>\n' +
    '#3 0x5611b953026e <unknown>\n' +
    '#4 0x5611b958080c <unknown>\n' +
    '#5 0x5611b9574e53 <unknown>\n' +
    '#6 0x5611b953cdd4 <unknown>\n' +
    '#7 0x5611b953e1de <unknown>\n' +
    '#8 0x5611b9807531 <unknown>\n' +
    '#9 0x5611b980b455 <unknown>\n' +
    '#10 0x5611b97f3f55 <unknown>\n' +
    '#11 0x5611b980c0ef <unknown>\n' +
    '#12 0x5611b97d799f <unknown>\n' +
    '#13 0x5611b9830008 <unknown>\n' +
    '#14 0x5611b98301d7 <unknown>\n' +
    '#15 0x5611b9842124 <unknown>\n' +
    '#16 0x7f9436572609 start_thread\n'
}

Node.js v18.17.1
root@NekoServer:~#

At first, I thought it was a problem with chromedriver, so I tried to manually install chromedriver.

wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/120.0.6099.109/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
mv chromedriver-linux64/chromedriver /usr/bin/
rm -rf chromedriver-linux64
chromedriver --version

(The latest version of ChromeDriver can be found here)

Then I ran it again and found that the problem still existed. Then I accidentally executed google-chrome and I understood.

3

It turns out that this thing cannot be run under the root user normally. It has to be run with the --no-sandbox parameter.

4

I found the Options CV in a project I wrote in an unknown grade, and added a line --no-sandbox, and ran it again.

5

Then it worked.
┐(´-`)┌

This article is synchronized and updated to xLog by Mix Space.
The original link is https://blog.nekorua.com/posts/technology/103.html


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.