LoginSignup
16
4

More than 5 years have passed since last update.

Cloud Functions で Puppeteer が動かないとき

Last updated at Posted at 2019-04-05

Puppeteer は、Google の Chrome DevTools Teams が開発しているブラウザの自動化ライブラリ。Cloud Functions でも使えると発表されている。

Introducing headless Chrome support in Cloud Functions and App Engine | Google Cloud Blog

が、Cloud Functions で動かしたときのみ、Navigation Timeout Exceeded エラーなどで Puppeteer が動かないときがある(動くときもあるので厄介)。
(ちなみにスペックは、runtime: Node.js 8, memory: 2GB, region: asia-northeast1

:warning: Navigation Timeout Exceeded エラー は、時間内に処理が完了しないときに出るエラーだが、Cloud functions が原因の場合は、timeout をどんなに長く設定してもダメ。

Puppeteer (Chromium) の起動オプションを見直す

Puppeteer slow execution on Cloud Functions · Issue #3120 · GoogleChrome/puppeteer

この issue でもいろいろ議論されている。

  const browser = await puppeteer.launch({
    args: [
      '--no-sandbox',
      '--disable-setuid-sandbox',
      '-–disable-dev-shm-usage',
      '--disable-gpu',
      '--no-first-run',
      '--no-zygote',
      '--single-process',
    ],
    headless: true,
  });

真似して設定してみたら、動いた :open_mouth:
同じ環境で困っていたら、試してみてくだしあ。

Chromium のオプション一覧
List of Chromium Command Line Switches « Peter Beverloo

16
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
4