puppeteer: TypeError: Cannot read property 'call' of null

This gets tricky since I can’t really provide you the best steps to reproduce. We have a flow that opens in a popup. Once you click the final “Done” button, it dismisses the popup. In the latest versions of Puppeteer (1.12.0+) this seems to also close the page that opened the popup (This should not be happening. This page should redirect.)

This issue does NOT occur on Puppeteer 1.10.0. (I suspect the issue may actually lie in Chromium, but figured I’d start here.)

Tell us about your environment:

  • Puppeteer version: 1.13.0
  • Platform / OS version: macOS 10.14.2
  • Node.js version: 10.15.0

What steps will reproduce the problem?

I can’t really provide a code snippet, but essentially we perform a page.click(doneButton);, the click is successful, then after a second or two both the popup, and the original page are torn down (the entire browser, actually) and this error is thrown:

TypeError: Cannot read property 'call' of null

      at DOMWorld._setContext (../../node_modules/puppeteer/lib/DOMWorld.js:61:36)
      at FrameManager._onExecutionContextCreated (../../node_modules/puppeteer/lib/FrameManager.js:303:13)
      at CDPSession.FrameManager._client.on.event (../../node_modules/puppeteer/lib/FrameManager.js:52:70)
      at CDPSession._onMessage (../../node_modules/puppeteer/lib/Connection.js:200:12)
      at Connection._onMessage (../../node_modules/puppeteer/lib/Connection.js:112:17)
      at WebSocketTransport._ws.addEventListener.event (../../node_modules/puppeteer/lib/WebSocketTransport.js:41:24)
      at WebSocket.onMessage (../../node_modules/ws/lib/event-target.js:120:16)
      at Receiver.receiverOnMessage (../../node_modules/ws/lib/websocket.js:741:20)

I’m aware this is probably not enough to go on, so if there are additional logs that I can grab (and you can provide me with instructions on how to grab them) I’d be happy to provide some more logging.

What is the expected result? Original page should remain and redirect.

What happens instead? Original page is destroyed and the entire browser instance is closed.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

My tests start failing today with the exact same errors (early termination). I’m using puppeteer with browserless

(node:57) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'call' of null
    at DOMWorld._setContext (/opt/app/node_modules/puppeteer/lib/DOMWorld.js:61:36)
    at FrameManager._onExecutionContextCreated (/opt/app/node_modules/puppeteer/lib/FrameManager.js:303:13)
    at CDPSession.FrameManager._client.on.event (/opt/app/node_modules/puppeteer/lib/FrameManager.js:52:70)
    at CDPSession.emit (events.js:193:13)
    at CDPSession._onMessage (/opt/app/node_modules/puppeteer/lib/Connection.js:200:12)
    at Connection._onMessage (/opt/app/node_modules/puppeteer/lib/Connection.js:112:17)
    at WebSocketTransport._ws.addEventListener.event (/opt/app/node_modules/puppeteer/lib/WebSocketTransport.js:41:24)
    at WebSocket.onMessage (/opt/app/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:193:13)
    at Receiver.receiverOnMessage (/opt/app/node_modules/ws/lib/websocket.js:741:20)

it’s still happening for me and 1.14

hi @joelgriffith, just tried your pull request myself however it doesnt look like that has fixed anything for me. still seeing

puppet_1       | (node:17) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'call' of null
puppet_1       |     at DOMWorld._setContext (/app/puppet/node_modules/puppeteer/lib/DOMWorld.js:61:36)
puppet_1       |     at FrameManager._onExecutionContextCreated (/app/puppet/node_modules/puppeteer/lib/FrameManager.js:319:13)
puppet_1       |     at CDPSession.FrameManager._client.on.event (/app/puppet/node_modules/puppeteer/lib/FrameManager.js:53:70)
puppet_1       |     at CDPSession.emit (events.js:189:13)
puppet_1       |     at CDPSession._onMessage (/app/puppet/node_modules/puppeteer/lib/Connection.js:200:12)
puppet_1       |     at Connection._onMessage (/app/puppet/node_modules/puppeteer/lib/Connection.js:112:17)
puppet_1       |     at WebSocketTransport._ws.addEventListener.event (/app/puppet/node_modules/puppeteer/lib/WebSocketTransport.js:41:24)
puppet_1       |     at WebSocket.onMessage (/app/puppet/node_modules/ws/lib/event-target.js:120:16)
puppet_1       |     at WebSocket.emit (events.js:189:13)
puppet_1       |     at Receiver.receiverOnMessage (/app/puppet/node_modules/ws/lib/websocket.js:789:20)
puppet_1       |     at Receiver.emit (events.js:189:13)
puppet_1       |     at Receiver.dataMessage (/app/puppet/node_modules/ws/lib/receiver.js:422:14)
puppet_1       |     at Receiver.getData (/app/puppet/node_modules/ws/lib/receiver.js:352:17)
puppet_1       |     at Receiver.startLoop (/app/puppet/node_modules/ws/lib/receiver.js:138:22)
puppet_1       |     at Receiver._write (/app/puppet/node_modules/ws/lib/receiver.js:74:10)
puppet_1       |     at doWrite (_stream_writable.js:410:12)
puppet_1       |     at writeOrBuffer (_stream_writable.js:394:5)
puppet_1       |     at Receiver.Writable.write (_stream_writable.js:294:11)
puppet_1       |     at Socket.socketOnData (/app/puppet/node_modules/ws/lib/websocket.js:864:35)
puppet_1       |     at Socket.emit (events.js:189:13)
puppet_1       |     at addChunk (_stream_readable.js:284:12)
puppet_1       |     at readableAddChunk (_stream_readable.js:265:11)

I can confirm it’s happening randomly as well inside of browserless. Randomly seeing it on 1.13.0, haven’t tried 1.14.0 yet. For me, it happens when listening to browser.on('targetcreated') event and doing operations on the target if it’s a page. It’s incredibly hard to reliably reproduce, but I’ll try using a debug statement.

Here’s a dump of protocol messages:

puppeteer:protocol ◀ RECV {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"c6dff360-1106-4660-b4aa-59364ac5130c","type":"browser","title":"","url":"","attached":false}}} +10ms
  puppeteer:protocol ◀ RECV {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"c6dff360-1106-4660-b4aa-59364ac5130c","type":"browser","title":"","url":"","attached":true}}} +0ms
  puppeteer:protocol ◀ RECV {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"03718C5A63E08AEC53FEBAD801D99D29","type":"page","title":"","url":"","attached":false,"browserContextId":"185273DBDFFF6BB24E37F02DE083FDA3"}}} +3ms
  puppeteer:protocol ◀ RECV {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"1C4543CEC50CF0C8BC09834776A40513","type":"page","title":"about:blank","url":"about:blank","attached":false,"browserContextId":"185273DBDFFF6BB24E37F02DE083FDA3"}}} +39ms
  puppeteer:protocol ◀ RECV {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"03718C5A63E08AEC53FEBAD801D99D29","type":"page","title":"about:blank","url":"about:blank","attached":false,"browserContextId":"185273DBDFFF6BB24E37F02DE083FDA3"}}} +20ms
  puppeteer:protocol SEND ► {"method":"Target.attachToTarget","params":{"targetId":"03718C5A63E08AEC53FEBAD801D99D29","flatten":true},"id":2} +0ms
  puppeteer:protocol ◀ RECV {"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"03718C5A63E08AEC53FEBAD801D99D29","type":"page","title":"about:blank","url":"about:blank","attached":true,"browserContextId":"185273DBDFFF6BB24E37F02DE083FDA3"}}} +1ms
  puppeteer:protocol ◀ RECV {"method":"Target.attachedToTarget","params":{"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","targetInfo":{"targetId":"03718C5A63E08AEC53FEBAD801D99D29","type":"page","title":"about:blank","url":"about:blank","attached":true,"browserContextId":"185273DBDFFF6BB24E37F02DE083FDA3"},"waitingForDebugger":false}} +0ms
  puppeteer:protocol ◀ RECV {"id":2,"result":{"sessionId":"A51E2AAB47D750A158B233985A1F8F8E"}} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Page.enable","params":{},"id":3} +0ms
  puppeteer:protocol ◀ RECV {"id":3,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +1ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Page.getFrameTree","params":{},"id":4} +1ms
  puppeteer:protocol ◀ RECV {"id":4,"result":{"frameTree":{"frame":{"id":"03718C5A63E08AEC53FEBAD801D99D29","loaderId":"60AB5BC19EBD10DFD0AF02960322ED6F","url":"about:blank","securityOrigin":"://","mimeType":"text/html"}}}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":false,"flatten":true},"id":5} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Page.setLifecycleEventsEnabled","params":{"enabled":true},"id":6} +1ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Network.enable","params":{},"id":7} +14ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Runtime.enable","params":{},"id":8} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Security.enable","params":{},"id":9} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Performance.enable","params":{},"id":10} +1ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Log.enable","params":{},"id":11} +0ms
  puppeteer:protocol ◀ RECV {"id":5,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Security.securityStateChanged","params":{"securityState":"neutral","schemeIsCryptographic":false,"explanations":[],"insecureContentStatus":{"ranMixedContent":false,"displayedMixedContent":false,"containedMixedForm":false,"ranContentWithCertErrors":false,"displayedContentWithCertErrors":false,"ranInsecureContentStyle":"unknown","displayedInsecureContentStyle":"unknown"},"summary":""}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"id":9,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"03718C5A63E08AEC53FEBAD801D99D29","loaderId":"60AB5BC19EBD10DFD0AF02960322ED6F","name":"commit","timestamp":286891.998493}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"03718C5A63E08AEC53FEBAD801D99D29","loaderId":"60AB5BC19EBD10DFD0AF02960322ED6F","name":"DOMContentLoaded","timestamp":286891.998557}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +16ms
  puppeteer:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"03718C5A63E08AEC53FEBAD801D99D29","loaderId":"60AB5BC19EBD10DFD0AF02960322ED6F","name":"load","timestamp":286891.998701}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"03718C5A63E08AEC53FEBAD801D99D29","loaderId":"60AB5BC19EBD10DFD0AF02960322ED6F","name":"networkAlmostIdle","timestamp":286891.999122}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Page.lifecycleEvent","params":{"frameId":"03718C5A63E08AEC53FEBAD801D99D29","loaderId":"60AB5BC19EBD10DFD0AF02960322ED6F","name":"networkIdle","timestamp":286891.999122}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"id":6,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +17ms
  puppeteer:protocol ◀ RECV {"id":7,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"origin":"://","name":"","auxData":{"isDefault":true,"type":"default","frameId":"03718C5A63E08AEC53FEBAD801D99D29"}}}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"id":8,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"id":10,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"id":11,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +1ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Page.addScriptToEvaluateOnNewDocument","params":{"source":"//# sourceURL=__puppeteer_evaluation_script__","worldName":"__puppeteer_utility_world__"},"id":12} +0ms
  puppeteer:protocol ◀ RECV {"id":12,"result":{"identifier":"1"}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +1ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Page.createIsolatedWorld","params":{"frameId":"03718C5A63E08AEC53FEBAD801D99D29","grantUniveralAccess":true,"worldName":"__puppeteer_utility_world__"},"id":13} +0ms
  puppeteer:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"context":{"id":2,"origin":"","name":"__puppeteer_utility_world__","auxData":{"isDefault":false,"type":"isolated","frameId":"03718C5A63E08AEC53FEBAD801D99D29"}}}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +2ms
  puppeteer:protocol ◀ RECV {"id":13,"result":{"executionContextId":2}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Emulation.setDeviceMetricsOverride","params":{"mobile":false,"width":800,"height":600,"deviceScaleFactor":1,"screenOrientation":{"angle":0,"type":"portraitPrimary"}},"id":14} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Emulation.setTouchEmulationEnabled","params":{"enabled":false},"id":15} +0ms
  puppeteer:protocol ◀ RECV {"id":14,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +1ms
  puppeteer:protocol ◀ RECV {"id":15,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol SEND ► {"sessionId":"A51E2AAB47D750A158B233985A1F8F8E","method":"Page.setDownloadBehavior","params":{"behavior":"allow","downloadPath":"/var/folders/sf/v91_lddx62d83njrwsh_5qrw0000gn/T"},"id":16} +1ms
  puppeteer:protocol ◀ RECV {"method":"Runtime.executionContextCreated","params":{"context":{"id":3,"origin":"","name":"__puppeteer_utility_world__","auxData":{"isDefault":false,"type":"isolated","frameId":"03718C5A63E08AEC53FEBAD801D99D29"}}}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +0ms
  puppeteer:protocol ◀ RECV {"id":16,"result":{}, "sessionId": "A51E2AAB47D750A158B233985A1F8F8E"} +1ms
(node:50745) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'call' of null
    at DOMWorld._setContext (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/lib/DOMWorld.js:61:36)
    at FrameManager._onExecutionContextCreated (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/lib/FrameManager.js:303:13)
    at CDPSession.FrameManager._client.on.event (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/lib/FrameManager.js:52:70)
    at CDPSession.emit (events.js:182:13)
    at CDPSession._onMessage (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/lib/Connection.js:200:12)
    at Connection._onMessage (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/lib/Connection.js:112:17)
    at WebSocketTransport._ws.addEventListener.event (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/lib/WebSocketTransport.js:41:24)
    at WebSocket.onMessage (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:182:13)
    at Receiver.receiverOnMessage (/Users/joelgriffith/browserless/chrome/node_modules/puppeteer/node_modules/ws/lib/websocket.js:792:20)

EDITED: Smaller example

Another info byte: apparently these flows run locally just fine (with Puppeteer 1.13.0 as well) in headless: true mode. This behavior appears consistent.

(Edit: forgot to mention I work with @weworkwithzoh, though that may have been implied 😃)

Adding some more context: the flow in question is a well-known 3rd party login provider, that is supposed to close the popup and redirect the originating window. We’re using the normal jest-puppeteer preset with no custom configuration or anything. The outcome depends on whether or not we’re running the flow manually, automatically (via Puppeteer), or automatically as part of our regular CI process. To be precise, here’s our current experience:

  • Running locally on MacOS Mojave with Puppeteer 1.10.0 - passes
  • Running locally on MacOS Mojave with Puppeteer 1.13.0 - fails (TypeError: Cannot read property 'call' of null)
  • Running manually on MacOS Mojave with Puppeteer 1.13.0’s version of Chromium (I’ve dumped the Puppeteer flags, see below) - passes • Running on CI (Linux/Dockerized) with Puppeteer 1.10.0 - fails (random timeout) • Running on CI (Linux/Dockerized) with Puppeteer 1.13.0 - fails (random timeout)

Chromium flags as generated by Puppeteer (redacted):

/Users/myuser/dev/projectname/node_modules/puppeteer/.local-chromium/mac-637110/chrome-mac/Chromium.app/Contents/MacOS/Chromium --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=site-per-process,TranslateUI,BlinkGenPropertyTrees --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --safebrowsing-disable-auto-update --enable-automation --password-store=basic --use-mock-keychain about:blank --user-agent=Chrome --no-sandbox --disable-setuid-sandbox --disable-popup-blocking --incognito --window-size=1440,900 --remote-debugging-port=0 --user-data-dir=--user-data-dir=/var/folders/jz/nwn1s1ls3x73j55bs87fcrlc0000gp/T/puppeteer_dev_profile-Lg0yCg

Hope this adds some context, we’d be more than happy to produce more logs, run experiments, basically anything short of sharing the codebase 😃