iDerekLi / juejin-helper

稀土掘金助手:签到、抽奖、沾喜气、消除Bug、海底掘金游戏、自动化工作流。
https://juejin.cn/post/7005379088491741215
Apache License 2.0
252 stars 1.08k forks source link

Centos环境下报错:浏览器API异常 #113

Open stick-i opened 1 year ago

stick-i commented 1 year ago

我当前的环境是Centos7,我参照项目文档的Juejin Workflows 掘金工作流 这一部分,配置了相关的参数。

当我在Linux上运行时,发生了一个错误:浏览器API异常。 但我在自己的windows上,以及GithubActions上运行,都没有出现这个问题。

于是我去拉取了项目的代码,找到了这行小字所在的位置。我把这段代码的try catch给注释掉了,然后再次让它运行,它抛出了这样的异常:

[root@aliyun juejin-helper-back]# yarn
yarn install v1.22.19
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.15s.
[root@aliyun juejin-helper-back]# yarn checkin
yarn run v1.22.19
$ ts-node checkin.js
/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
checkin.js:220:5 - error TS1434: Unexpected keyword or identifier.

220     console.log("-------------------------");
        ~~~~~~~
checkin.js:220:12 - error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.

220     console.log("-------------------------");
               ~
checkin.js:220:17 - error TS1003: Identifier expected.

220     console.log("-------------------------");
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
checkin.js:222:1 - error TS1128: Declaration or statement expected.

222 }
    ~

    at createTSError (/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
    at Object.require.extensions.<computed> [as .js] (/usr/juejin/juejin-helper-back/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1043:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  diagnosticCodes: [ 1434, 1068, 1003, 1128 ]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

image

我windows上的node版本和Linux上一样,应该不是版本的问题。

我是一名Java开发者,对JS并不熟悉,希望作者能帮我看一看这个问题,非常感谢!

stick-i commented 1 year ago

不好意思,我少删了一个},所以我上面放的那个异常并不是导致 “浏览器API异常” 的原因。

以下这个才是:

[root@aliyun juejin-helper-back]# yarn checkin
yarn run v1.22.19
$ ts-node checkin.js
--------模拟访问---------
Error: Failed to launch the browser process!
/root/.cache/puppeteer/chrome/linux-1069273/chrome-linux/chrome: error while loading shared libraries: libatk-bridge-2.0.so.0: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/BrowserRunner.ts:328:9)
    at Interface.<anonymous> (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/BrowserRunner.ts:314:16)
    at Interface.emit (node:events:406:35)
    at Interface.emit (node:domain:475:12)
    at Interface.close (node:readline:586:8)
    at Socket.onend (node:readline:277:10)
    at Socket.emit (node:events:406:35)
    at Socket.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
stick-i commented 1 year ago

我通过newbing,安装了一些依赖在我的centos7上,但仍然无法正常运行,它总有一些奇奇怪怪的错误

我使用root用户执行时

yarn run v1.22.19
$ ts-node checkin.js
--------模拟访问---------
Error: Failed to launch the browser process!
[0323/221802.690218:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/BrowserRunner.ts:328:9)
    at Interface.<anonymous> (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/BrowserRunner.ts:314:16)
    at Interface.emit (node:events:406:35)
    at Interface.emit (node:domain:475:12)
    at Interface.close (node:readline:586:8)
    at Socket.onend (node:readline:277:10)
    at Socket.emit (node:events:406:35)
    at Socket.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我使用jenkins用户执行时:

yarn run v1.22.19
$ ts-node checkin.js
--------模拟访问---------
Error: Could not find Chromium (rev. 1069273). This can occur if either
 1. you did not perform an installation before running the script (e.g. `npm install`) or
 2. your cache path is incorrectly configured (which is: /var/lib/jenkins/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
    at ChromeLauncher.resolveExecutablePath (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/ProductLauncher.ts:118:17)
    at ChromeLauncher.executablePath (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/ChromeLauncher.ts:247:19)
    at ChromeLauncher.launch (/usr/juejin/juejin-helper-back/node_modules/puppeteer-core/src/node/ChromeLauncher.ts:101:31)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

貌似Chrome的这个驱动对Centos的支持并不好,我发现Github Actions上用的是Ubuntu

iDerekLi commented 1 year ago

Centos还没有进行尝试过, 但Ubuntu是没问题的

iDerekLi commented 1 year ago

Centos还没有进行尝试过, 但Ubuntu是没问题的

stick-i commented 1 year ago

Centos还没有进行尝试过, 但Ubuntu是没问题的

😢😢😢是这样的

munan56 commented 1 year ago

same

ianding commented 8 months ago

关闭沙盒就好了

stick-i commented 8 months ago

关闭沙盒就好了

@ianding 能详细说说吗?

ianding commented 8 months ago

关闭沙盒就好了

@ianding 能详细说说吗?

const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], });

增加args参数,但是官方不推荐,可以使用推荐的另两种方法https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix