4

I've started working with Puppeteer and for some reason I cannot get it to work on my box. This error seems to be a common problem (SO1, SO2) but all of the solutions do not solve this error for me. I have tested it with a clean node package (see reproduction) and I have taken the example from the official Puppeteer 'Getting started' webpage.

How can I resolve this error?

Versions and hardware

/tmp/so_example » uname -a
Linux tom.arch 5.15.2-arch1-1 #1 SMP PREEMPT Fri, 12 Nov 2021 19:22:10 +0000 x86_64 GNU/Linux
/tmp/so_example » node --version
v17.1.0
/tmp/so_example » npm list
so_example@1.0.0 /tmp/so_example
└── puppeteer@11.0.0
/tmp/so_example » cat /proc/meminfo
MemTotal:       32492764 kB
MemFree:          600032 kB
MemAvailable:   24446556 kB
Buffers:         7149964 kB
Cached:          9549048 kB
SwapCached:            0 kB
Active:          9843552 kB
Inactive:       10980476 kB
Active(anon):     462692 kB
Inactive(anon):  5481100 kB
Active(file):    9380860 kB
Inactive(file):  5499376 kB
Unevictable:      723108 kB
Mlocked:           17336 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:       4848276 kB
Mapped:           625156 kB
Shmem:           1816292 kB
KReclaimable:    9438608 kB
Slab:           10007568 kB
SReclaimable:    9438608 kB
SUnreclaim:       568960 kB
KernelStack:       26240 kB
PageTables:        63012 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    16246380 kB
Committed_AS:   16256172 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      103964 kB
VmallocChunk:          0 kB
Percpu:            14592 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:     5072608 kB
DirectMap2M:    20758528 kB
DirectMap1G:     7340032 kB
/tmp/so_example » lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  16
  On-line CPU(s) list:   0-15
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
    CPU family:          6
    Model:               165
    Thread(s) per core:  2
    Core(s) per socket:  8
    Socket(s):           1
    Stepping:            2
    CPU max MHz:         5100.0000
    CPU min MHz:         800.0000
    BogoMIPS:            4601.60
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology
                         nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnow
                         prefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt inte
                         l_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp pku ospke sgx_lc md_clear flush_l1d arch_capabilities
Virtualization features:
  Virtualization:        VT-x
Caches (sum of all):
  L1d:                   256 KiB (8 instances)
  L1i:                   256 KiB (8 instances)
  L2:                    2 MiB (8 instances)
  L3:                    16 MiB (1 instance)
NUMA:
  NUMA node(s):          1
  NUMA node0 CPU(s):     0-15
Vulnerabilities:
  Itlb multihit:         KVM: Mitigation: VMX disabled
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
  Srbds:                 Not affected
  Tsx async abort:       Not affected

Reproduction

/tmp/so_example » npm init -y
Wrote to /tmp/so_example/package.json:

{
  "name": "so_example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
/tmp/so_example » npm i puppeteer
added 57 packages, and audited 58 packages in 11s

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
/tmp/so_example » npm list
so_example@1.0.0 /tmp/so_example
└── puppeteer@11.0.0
/tmp/so_example » echo "const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://google.com');
  await browser.close();
})();" > example.js
/tmp/so_example » nvm use 17
Now using node v17.1.0 (npm v8.1.2)

/tmp/so_example » node example.js
/tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226
                error: new Errors_js_1.ProtocolError(),
                       ^

ProtocolError: Protocol error (Page.navigate): Target closed.
    at /tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:24
    at new Promise (<anonymous>)
    at CDPSession.send (/tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:222:16)
    at navigate (/tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:148:47)
    at FrameManager.navigateFrame (/tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:131:13)
    at Frame.goto (/tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:500:41)
    at Page.goto (/tmp/so_example/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:1167:53)
    at /tmp/so_example/example.js:6:14
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  originalMessage: undefined
}

Node.js v17.1.0

I get the same error with the following versions:

/tmp/so_example » nvm use 16
Now using node v16.13.0 (npm v8.1.0)
/tmp/so_example » nvm use 15
Now using node v15.14.0 (npm v7.7.6)
/tmp/so_example » nvm use 14
Now using node v14.18.1 (npm v6.14.15)

Update: Docker

I've also tried the same installation on Docker following this guide. With this setup it seems to work. This suggests it is an OS/package related issue.

/tmp/so_example » echo "const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({
    headless: true,
    args: [
        '--disable-gpu',
        '--disable-dev-shm-usage',
        '--disable-setuid-sandbox',
        '--no-sandbox',
    ]
  });
  const page = await browser.newPage();
  await page.goto('https://google.com');


  await browser.close();
  console.log('If I made it here there is no error');
})();" > example.js
/tmp/so_example » echo "FROM node:17-slim

# Chrome dependencies
RUN apt-get update && apt-get -f install -y \\
    fonts-liberation \\
    gconf-service \\

    #libappindicator1 \\

    libasound2 \\
    libatk1.0-0 \\
    libcairo2 \\
    libcups2 \\
    libfontconfig1 \\
    libgbm-dev \\
    libgdk-pixbuf2.0-0 \\
    libgtk-3-0 \\
    libicu-dev \\
    libjpeg-dev \\
    libnspr4 \\
    libnss3 \\
    libpango-1.0-0 \\
    libpangocairo-1.0-0 \\
    libpng-dev \\
    libx11-6 \\
    libx11-xcb1 \\
    libxcb1 \\
    libxcomposite1 \\
    libxcursor1 \\
    libxdamage1 \\
    libxext6 \\
    libxfixes3 \\
    libxi6 \\
    libxrandr2 \\
    libxrender1 \\
    libxss1 \\
    libxtst6 \\
    xdg-utils

COPY . ./
RUN npm install

# Make browser executable for puppeteer
RUN chmod -R o+rwx node_modules/puppeteer/.local-chromium

CMD [\"node\", \"example.js\"]" > Dockerfile
/tmp/so_example » docker run -it $(docker build -q .)
If I made it here there is no error

Edit: static chromium path

As commented on this question, adding

executablePath: 'path/to/local/chromium'

to the puppeteer configuration makes the reproduction run on the system. I would still like to know why the chromium packaged with puppeteer does not work as using a static path to a local executable is a really bad practice in a multi-dev environment.

Tom Stock
  • 1,098
  • 1
  • 12
  • 26
  • Lots of things can cause that. Not enough ram? Can you open google in normal chrome? – pguardiario Nov 22 '21 at 08:09
  • I've added my hardware specs, which I do not think are the issue. Opening chrome via the arch 'chromium' package is no problem for me. – Tom Stock Nov 22 '21 at 08:15
  • I'm just tagging you @pguardiario as I just found out you're otherwise not getting notified ;p – Tom Stock Nov 22 '21 at 08:26
  • I would try launching with {executablePath: '/path/to/working/chromium'} – pguardiario Nov 22 '21 at 08:49
  • @pguardiario That works! Though I would still like to know why it does not work with the provided chromium package by puppeteer. As using a static path won't scale well in a multi-dev environment. This does narrow it down to the chromium package of puppeteer though! – Tom Stock Nov 22 '21 at 08:58
  • Well another idea is to check the version of working chromium and use a corresponding puppeteer version. Each puppeteer version comes with a different chromium version. – pguardiario Nov 23 '21 at 01:59
  • @TomStock I think the offending code is here: https://github.com/puppeteer/puppeteer/blob/main/src/node/BrowserFetcher.ts in the ` revisionInfo` function. I dealt with something similar on RHEL 7. I am using `executablePath` , but I also have this in my options: `ignoreDefaultArgs: [ '--disable-extensions' ]`. It's so long ago. I don't remember why I needed it, but it was related to this error in someway and found it burried deep in a Google search. Maybe it will help. – dj11223344 Nov 24 '21 at 18:08
  • Any updates on this issue? I have been struggling with this for 3 days. Passing the local path of chromium to `executablePath` solves the issue but does not scale very well –  Nov 27 '21 at 05:47

2 Answers2

1

Surprisingly, after updating to Puppeteer version 12.0.0, everything seems to work. As of yet I do not know what caused the issue and what made it go away, but it works now.

EDIT: The changelog can be found here, and presumably the update to Chromium 97.0.4692.0 is what resolved the issue.

Tom Stock
  • 1,098
  • 1
  • 12
  • 26
0

There's too much for me to put this in a comment, so I will summarize here. Maybe it will help you, or someone else. I should also mention this is for RHEL EC2 instances behind a corporate proxy (not Arch Linux), but I still feel like it may help. I had to do the following to get puppeteer working. This is straight from my docs, but I had to hand-jam the contents because my docs are on an intranet.

I had to install all of these libraries manually. I also don't know what the Arch Linux equivalents are. Some are duplicates from your question, but I don't think they all are:
pango libXcomposite libXcursor libXdamage libXext libXi libXtst cups-libs libXScrnSaver libXrandr GConf2 alsa-lib atk gtk3 ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc liberation-mono-fonts liberation-narrow-fonts liberation-narrow-fonts liberation-sans-fonts liberation-serif-fonts glib2

If Arch Linux uses SELinux, you may also have to run this:
setsebool -P unconfirmed_chrome_sandbox_transition 0

It is also worth adding dumpio: true to your options to debug. Should give you a more detailed output from puppeteer, instead of the generic error. As I mentioned in my comment. I have this option ignoreDefaultArgs: ['--disable-extensions']. I can't tell you why because I don't remember. I think it is related to this issue, but also could be related to my corporate proxy.

dj11223344
  • 113
  • 12
  • I have tried this and unfortunately it does not work. Updating to puppeteer@12.0.0 did solve the issue though! However, I still have no clue as to why it suddenly works. – Tom Stock Nov 28 '21 at 07:24