puppeteer: Using esm (ES6 modules) causes failure.
Steps to reproduce
Tell us about your environment:
- Puppeteer version: 6.4.1
- Platform / OS version: Linux latitude 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- URLs (if applicable):
- Node.js version: 10.10.0
What steps will reproduce the problem?
Please include code that reproduces the issue.
- copy example code into a new file example.js
- replace
const puppeteer = require('puppeteer')withìmport puppeteer from 'puppeteer' - run with
node -r esm example.js
What is the expected result?
Empty prompt, example.png in script folder.
What happens instead?
node -r esm demo.js
(node:11730) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'on' of undefined
at Function.addEventListener (../node_modules/puppeteer/lib/helper.js:165:13)
at new NavigatorWatcher (../node_modules/puppeteer/lib/FrameManager.js:1146:14)
at FrameManager.navigateFrame (../node_modules/puppeteer/lib/FrameManager.js:75:21)
at Frame.goto (../node_modules/puppeteer/lib/FrameManager.js:404:37)
at Page.goto (../node_modules/puppeteer/lib/Page.js:579:49)
at require (../demo.js:6:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:11730) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 20 (6 by maintainers)
Commits related to this issue
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome) - Breaking change (minor): `svg.Property` (2nd arg) (and `svg.ViewPor... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
- INCOMPLETE: Finish testing (stuck until https://github.com/GoogleChrome/puppeteer/issues/3382 unless npx babel-node will overcome); For startsWith/endsWith requires: - Breaking change: Require `@babel... — committed to brettz9/canvg by brettz9 6 years ago
Yes, likely within a
week or so.Well that week-or-so turned into a bit longer with the US Thanksgiving holiday. I should release before I start more aggressive perf work. I’ll ping back this thread when it’s released.
BTW, I had this issue with puppeteer
1.9.0, had to roll back to1.8.0which didn’t produce the error. Then accidentally updated it1.11.0and it just worked! Here’s my setup: https://github.com/sergiitk/pagerbeauty/blob/122aca70976db520487906ac670b98d1177b275c/Dockerfile-test-acceptanceChromium 71 / Ava 1.0.1 / Puppetter 1.11.0 / Docker / Node 10.15.0-alpine
Thanks @aslushnikov!
I narrowed it down to a faulty
Symbol.hasInstancehelper on our end (https://github.com/standard-things/esm/commit/111328e69eafc25829508329e1b1d853951f7dc0).@jdalton awesome, reopening.
Thanks to @damianobarbati input, I’ve debugged it down to d547b9d. The core issue seems to be that an instance of
Connectionclass satisfies theinstanceofcheck againstCDPSessionclass.Here’s a small snippet from
Connectionclass (check out theconsole.logstatements):@jdalton any ideas what’s going on here?
@jdalton is the release done?
@aslushnikov after digging into the code I noted that this does not seem to not be related to ESM but to this line into into
Connection.js: https://github.com/GoogleChrome/puppeteer/blob/d547b9d24a803c0adf923b3a821ae5f43e79bb53/lib/Connection.js#L51 which is called here intoFrameManager.js: https://github.com/GoogleChrome/puppeteer/blob/c237947b324338ece670b4f4e879880265ec6965/lib/FrameManager.js#L1146connection._connectionisundefinedconnection instanceof CDPSessionis trueconnection._connectionwhich isundefinedis assigned toconnectionundefinedis not an instance ofCDPSession, “while” loop stops andundefinedis returnedhelper.addEventListener(Connection.fromSession(client), ..., ...)attempt to attach event onundefinedand the error is firedReplacing the following into https://github.com/GoogleChrome/puppeteer/blob/d547b9d24a803c0adf923b3a821ae5f43e79bb53/lib/Connection.js#L50 solves the issue
But I’m not sure whether that makes “logic” sense.
I’m using ava, which controls Node and compilation. This is the relevant issue:
https://github.com/avajs/ava/issues/1810
The error we’re seeing: