banner
libxcnya.so

libxcnya.so

Nothing...
telegram
twitter
github
email

在 Linux 环境下部署 Node.JS + Selenium 项目踩坑

前言#

由于博主的 Windows 服务器快过期了,所以之前跑在 Windows 机子上的东西得考虑往 Linux 上迁移
然后试图跑小学二年级写的 Shit Code 发现跑不起来
然后就有了今天的这篇水文

安装#

安装 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

(有一说一这地址在国内没墙)

输入 google-chrome --version 验证是否安装成功

1

如果正常输出版本就代表安装成功了

在 NPM 中,执行 npm install selenium-webdriver 理论上就能配好在 node 项目中使用的 chromedriver
就拿上个月写的答辩 Hostloc 刷分的小玩意举个例子吧
当时哥们所有的东西都装好后一跑就报错

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:~#

一时以为是 chromedriver 的问题,然后试图手动安装 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

(最新版 ChromeDriver 可以在 这里 找到)

然后又跑了一遍,发现还是这问题
然后我手贱执行了一下 google-chrome 哦我明白了

3

原来这玩意正常情况下不能跑在 root 用户底下,非要跑得加个参数 --no-sandbox

4

找到不知道几年级写的项目里面把 Options CV 过来,然后加上一行 --no-sandbox,再跑一次

5

然后就能跑了
┐(´-`)┌

此文由 Mix Space 同步更新至 xLog
原始链接为 https://blog.nekorua.com/posts/technology/103.html


加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。