Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 519
harsh989 Avatar asked Dec 08 '18 09:12

harsh989


People also ask

What is no sandbox in Chrome?

The Google Chrome Sandbox is a development and test environment for developers working on Google Chrome browser-based applications. The sandbox environment provides a testing and staging platform without allowing the code being tested to make changes to existing code and databases.

How do I use puppeteer to open Chrome?

By default, Puppeteer downloads and uses a specific version of Chromium so its API is guaranteed to work out of the box. To use Puppeteer with a different version of Chrome or Chromium, pass in the executable's path when creating a Browser instance: const browser = await puppeteer.

Does puppeteer work with Chrome?

Puppeteer is a Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium.

What browser does puppeteer use?

Puppeteer uses Chrome DevTools protocol and the debugger protocol for Selenium is JSONWire. Both are used to perform clicks.


1 Answers

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.

like image 174
theDavidBarton Avatar answered Sep 23 '22 12:09

theDavidBarton