Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stick-i opened this issue Mar 23, 2023 · 9 comments
Open

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

stick-i opened this issue Mar 23, 2023 · 9 comments

Comments

@stick-i
Copy link

stick-i commented Mar 23, 2023

我当前的环境是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
Copy link
Author

stick-i commented Mar 23, 2023

不好意思,我少删了一个},所以我上面放的那个异常并不是导致 “浏览器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
Copy link
Author

stick-i commented Mar 23, 2023

我通过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
Copy link
Owner

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

1 similar comment
@iDerekLi
Copy link
Owner

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

@stick-i
Copy link
Author

stick-i commented Mar 27, 2023

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

😢😢😢是这样的

@munan56
Copy link

munan56 commented Jul 26, 2023

same

@ianding
Copy link

ianding commented Dec 28, 2023

关闭沙盒就好了

@stick-i
Copy link
Author

stick-i commented Dec 28, 2023

关闭沙盒就好了

@ianding 能详细说说吗?

@ianding
Copy link

ianding commented Dec 28, 2023

关闭沙盒就好了

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants