Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer/chromium on Mac chronically prompting "accept incoming network connection?"

I have a node application that uses puppeteer to test a web site. Up until we updated to latest puppeteer 1.12.2 we had no problem.

  1. Node launches puppeteer on timer
  2. On every launch, system asks: "Do you want to the application Chromium.app to accept incoming network connections"

In the Firewall tab of the "Security and Privacy" settings, ACCEPT is specifically set for Chromium. (and we've tried turning it off too) There seems to be no pleasing MacOS on this point.

Any suggestions about how to quiet MacOS and recognize/persist the firewall preference?

like image 806
Eric Oemig Avatar asked Feb 06 '19 00:02

Eric Oemig


3 Answers

We were having the same issue after upgrade our puppeteer and MacOS. One solution we have is to instruct puppeteer to use our own Chrome instead of the bundled chromium by specifying the executablePath. Below is a Typescript snippet how we specify it. Same thing if you use vanilla JS.

Sometimes that still is not enough, we have to make headless option false to make it consistently work, which is really annoying.

      /**
       * create a puppeteer 'Browser' object.
       */
      public static createBrowser(): Promise<Browser> {
        return puppeteer.launch({
          // ... other options
          headless: false,
          executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
        });
      }

Hope it also works for you. :-)

like image 107
LeOn - Han Li Avatar answered Nov 15 '22 06:11

LeOn - Han Li


Another option is self sign a certificate, follow the instructions in this comment:

https://github.com/GoogleChrome/puppeteer/issues/4752#issuecomment-524086077

Here in more detail how to open the Certificate creator: https://support.apple.com/en-gb/guide/keychain-access/kyca2686/mac)

And then in the root of your repo run:

sudo codesign -s MyCertificateName -f ./node_modules/puppeteer/.local-chromium/mac-674921/chrome-mac/Chromium.app --deep

like image 44
blub Avatar answered Nov 15 '22 07:11

blub


In my case it was using a globally installed version of chromium (from playwright). So the following command worked in signing it:

global chromium

sudo codesign --force --deep --sign - ~/Library/Caches/ms-playwright/chromium-*/chrome-mac/Chromium.app

If you don't use a global chromium install, the following might work

local project chromium

sudo codesign --force --deep --sign - ./node_modules/puppeteer/.local-chromium/mac-*/chrome-mac/Chromium.app
like image 34
Ben Winding Avatar answered Nov 15 '22 07:11

Ben Winding