Rails7のGroverで「Running as root without --no-sandbox is not supported.」のエラーが出た時の対応方法

created
updated

Ruby on Railsで利用できるGroverとは

GoogleのPuppeteerChromiumを使って、HTMLをPDF,PNG,JPEGに変換するRuby gemです。

Studiosity/grover: A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer/Chromium

Groverのエラー内容

Grover::JavaScript::Error in SampleController#action_name
Failed to launch the browser process!
[1019/015119.878885:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

Groverのエラーの対応方法

launch_argsのオプションに、--no-sandboxを追加するとエラーが解消されます。

# config/initializers/grover.rb

Grover.configure do |config|
  config.options = {
    ...
    launch_args: ['--lang=ja', '--no-sandbox'], # --lang=ja は日本語化のオプション
    ...
  }
end
TOP