Aaronius / penpal

A promise-based library for securely communicating with iframes via postMessage.
MIT License
389 stars 56 forks source link

Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window' #11

Closed jrencz closed 6 years ago

jrencz commented 6 years ago

I'm experimenting with Penpal and I try throwing things in and out from and to the child page I need to have embedded just to find out if Penpal can handle that. I'm very much satisfied and impressed with what it can do. Great piece of software!

I tried transferring child window object to parent which is obviously something that should fail. Disclaimer: This report is not about that Penpal is incapable of sending child window to parent. I'm aware why it fails and it's clear to me that no sane person should try to do that for any reason.

It's about the fact that doing such stupid thing (either on purpose or by mistake) should result in a failed promise returned by the child method called in parent, instead of an uncaught error in child (which happens now).

Promise in parent never resolves. It stays pending indefinitely which does not allow parent to handle problem caused by the child. Wrapping the child method call in try-catch in parent code does not allow detecting the problem either. And that's the main problem I see in this behaviour.

Exact error I saw in parent console:

index.js:234 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window': #<Window> could not be cloned.
    at http://localhost:3100/vendor.bundle.js:36215:21
    at <anonymous>

Line in question nad lines that follow:

remote.postMessage({
  penpal: REPLY,
  id: id,
  resolution: resolution,
  returnValue: returnValue
}, remoteOrigin);
Aaronius commented 6 years ago

Thanks for reporting this. Sounds like something we want to get fixed.

Aaronius commented 6 years ago

Fixed in 2.7.1.