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?
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.
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.
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.
Puppeteer uses Chrome DevTools protocol and the debugger protocol for Selenium is JSONWire. Both are used to perform clicks.
As Cloud Functions is serverless you can do not much more than using this Chromium flag at launch each time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With