【问题标题】:Why Puppeteer needs --no-sandbox to launch Chrome in Cloud Functions为什么 Puppeteer 需要 --no-sandbox 在 Cloud Functions 中启动 Chrome
【发布时间】:2019-05-09 21:45:29
【问题描述】:

当我使用 Node 8 在 Cloud Functions 上运行 Puppeteer 时,出现此错误。

Error: Failed to launch chrome!
[1205/063825.588245:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

启动 Puppeteer 与

browser = await puppeteer.launch({
    args: ['--no-sandbox'],
    headless: true
})

解决了这个问题。 我在互联网上搜索过,找不到任何需要这样做的理由?

为什么 Headless Chrome 首先以 root 身份运行?

【问题讨论】:

    标签: node.js firebase google-cloud-functions puppeteer google-chrome-headless


    【解决方案1】:

    由于 Cloud Functions 是无服务器的,因此您只能在每次启动时使用这个 Chromium 标志。

    背景

    --no-sandbox 标志的使用只是使浏览器在 Linux 系统上启动成为可能的一种解决方法。

    它与安全性有关,具体来说:Linux sandboxing,如果您要处理不受信任的网络流量,建议您为 Chromium 设置自己的沙箱,而不是使用没有的 chrome。

    您可以使用user namespace cloning 在 Linux 上设置发送箱。对于 Cloud Functions,我不知道是否可以设置任何解决方案:因此您需要 no-sandbox,但请确保您的 puppeteer 脚本仅访问受信任的页面。

    【讨论】:

      猜你喜欢
      • 2017-09-24
      • 2016-05-26
      • 2018-06-22
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      相关资源
      最近更新 更多