CentOS puppeteer 运行报Running as root without --no-sandbox is not supported.解决方式

运行代码提示

Error: Failed to launch the browser process!

/www/wwwroot/vtopworld/server/node_modules/[email protected]@puppeteer/.local-chromium/linux-938248/chrome-linux/chrome: error while loading shared。******* cannot open shared object file: No such file or directory。

执行linux命令行

sudo yum install -y chromium

继续提示报错信息:

Error: Failed to launch the browser process!

[0115/105742.718414:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

解决代码:

puppetteer.launch({headless: true,args: ['--no-sandbox']
})

test.js

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch({
   headless: true,
   args: ['--no-sandbox']
});
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({ path: 'example.png' });
  await browser.close();
})();

参考:

Fixed: CentOS 8 ---- Error: Failed to launch the browser process!

ERROR:zygote_host_impl_linux.cc(89) Running as root without --no-sandbox is not supported

你可能感兴趣的:(centos,linux,服务器)