为什么Puppeteer需要--no-sandbox才能在Cloud Functions中启动Chrome [英] Why Puppeteer needs --no-sandbox to launch Chrome in Cloud Functions

查看:182
本文介绍了为什么Puppeteer需要--no-sandbox才能在Cloud Functions中启动Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在具有节点8的Cloud Functions上运行Puppeteer时,出现此错误.

When I run Puppeteer on Cloud Functions with Node 8, I get this error.

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.

使用以下游戏启动木偶

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

解决了问题.我在互联网上搜索过,找不到任何必要的理由吗?

solves the issue. I have searched on the internet and could not find any reason why is this necessary?

为什么无头Chrome首先以root用户身份运行?

Why does Headless Chrome run as root in the first place?

推荐答案

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

As Cloud Functions is serverless you can do not much more than using this Chromium flag at launch each time.

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

The usage of --no-sandbox flag is only a workaround to make browser launch possible on Linux systems.

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

It is related to security, concretely: Linux sandboxing and it is advised to set up your own sandbox for Chromium if you are dealing with untrusted web traffic instead of using chrome without one.

您可以使用用户名称空间克隆.如果使用Cloud Functions,我不知道是否可以设置任何解决方案:因此,您需要 no-sandbox ,但请确保您的伪造者脚本仅访问受信任的页面.

You can set up a sendbox on Linux with user namespace cloning. In case of Cloud Functions I am not aware of any solutions if this could be set up: so you need the no-sandbox, but make sure your puppeteer scripts visiting only trusted pages.

这篇关于为什么Puppeteer需要--no-sandbox才能在Cloud Functions中启动Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆