node.js - 为什么 Puppeteer 需要 --no-sandbox 在 Cloud Functions 中启动 Chrome

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

当我使用 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 身份运行?

最佳答案

由于 Cloud Functions 是无服务器的,因此您只能在每次启动时使用此 Chromium 标志。
背景--no-sandbox的用法flag 只是在 Linux 系统上启动浏览器的一种解决方法。
它与安全有关,具体为:Linux sandboxing如果您正在处理不受信任的网络流量,建议为 Chromium 设置您自己的沙箱,而不是使用没有的 chrome。
您可以使用 user namespace cloning 在 Linux 上设置发送箱.对于 Cloud Functions,如果可以设置,我不知道有任何解决方案:所以您需要 no-sandbox ,但请确保您的 puppeteer 脚本仅访问受信任的页面。

关于node.js - 为什么 Puppeteer 需要 --no-sandbox 在 Cloud Functions 中启动 Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53681161/

相关文章:

node.js - 如何使用nodejs对mongodb进行软删除

MySQL:如何在有两个外键的表中插入值

node.js - MongoDB 搜索用户 : filter based on name with regex

firebase - 如何在不在每个屏幕中传递 'analytics/observer' 对象的情况下在 Flutter 中设置 Firebase Analytics 自定义事件

python-3.x - "pyarrow.lib.ArrowInvalid: Casting from timestamp[ns] to timestamp[ms] would lose data"在没有架构的情况下向 BigQuery 发送数据时

Node.js:如何使用异步模块执行无限循环

firebase - 无法获取 Firebase 存储安全规则来拒绝访问文件

javascript - Firebase Google 登录 token 过期问题

reactjs - React Hooks 不适用于 Firebase Cloud Functions 错误 : Invariant Violation: Invalid hook call

python-3.x - BigQuery 更新如何获取更新的行数