Why Puppeteer needs --no-sandbox to launch Chrome in Cloud Functions

╄→гoц情女王★ 提交于 2021-01-27 04:23:13

问题


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.

Launching Puppeteer with

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?

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


回答1:


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

Background

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

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.

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.



来源:https://stackoverflow.com/questions/53681161/why-puppeteer-needs-no-sandbox-to-launch-chrome-in-cloud-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!