LoginSignup
3
1

More than 3 years have passed since last update.

M1 MacBookでpuppeteerが動かない時の解決策

Posted at

端的にいうと、条件分岐で弾かれているからということのようです。
今後パッチで解決される可能性があります。公式で改善された場合は、この記事での対処は不要です。

puppeteerをインストールします

yarn add puppeteer

puppeteerのコードを変更します。

https://github.com/joshuajung/puppeteer/commit/7987b91069adafa260c8b795eab3b901847240f7
上記GitHubの記述を頼りに赤くなっている部分を消します。

vim [インストールしたフォルダ]/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js

vim [インストールしたフォルダ]/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js

Chroniumを入れる

https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Mac/818858/
のchrome-mac.zipをダウンロードし、アプリケーションフォルダに入れます。

自分が作ったスクリプトを変更する

puppeteerを起動する処理にexecutablePathの記述を追加します。

const browser = await puppeteer.launch({ 
            headless: false, 
            defaultViewport: {width: 1400, height: 2000 },
++          executablePath: '/Applications/Chromium.app/Contents/MacOS/Chromium',
        });

セキュリティの問題でChroniumが弾かれるので許可する

システム環境設定→セキュリティとプライバシーからChroniumを許可します。

puppetterが動くのを確認する

しっかりキャプチャできました!
PageSpeedInsights_1.sp_20210120134800.png

3
1
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
3
1