错误信息:
/www/wwwroot/www/node_modules/.store/@puppeteer+browsers@1.9.0/node_modules/@puppeteer/browsers/lib/cjs/launch.js:277
reject(new Error([
^
Error: Failed to launch the browser process!
[0102/153249.332099:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
TROUBLESHOOTING: https://pptr.dev/troubleshooting
at Interface.onClose (/www/wwwroot/www/node_modules/.store/@puppeteer+browsers@1.9.0/node_modules/@puppeteer/browsers/lib/cjs/launch.js:277:24)
原因:在CentOS下安装puppeteer模拟访问网页,但是运行JS脚本后报错,原因是Chrome无法再root账户下启动,需要配置--no-sandbox;我的起初想法是在下找到启动chrome的脚本配置上,但是却找不到具体文件在哪,查看手册才知道可以直接在脚本下进行配置。
错误代码:
const browser = await puppeteer.launch();
正确代码:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
args: ['--no-sandbox'],
});
const page = await browser.newPage();
// 你的其他代码...
await browser.close();
})();
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容