Aaronius / penpal

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

Cannot read property 'parentWindow' of null #27

Closed srhyne closed 5 years ago

srhyne commented 5 years ago

@Aaronius we are using Penpal for embedded lessons in ConveYour.com. We ❤️ it! Thank you!

I just upgraded from 3.0.7 to 3.1.0 and now we are getting this exception often. Here's the related line.

https://github.com/Aaronius/penpal/blob/843476f823b2b896b471ab02728aa8c715aaaf6c/src/index.js#L392

It looks like in the previous version this variable was set prior to handleMessage method being created so held in a closure (right?).

What should I change in my setup to make sure I'm compliant with this change? Thank you!

srhyne commented 5 years ago

More on this.. It seems as though, this handleMessage would only fire when the parent receives a message from the child and that's only going to happen when the child is already in the DOM. I'm going to try to do some console log's on this to figure out what event or iframe state is causing this.

Aaronius commented 5 years ago

@srhyne I ended up fixing this issue in this commit and releasing it in version 3.1.1. It doesn't resolve the concerns I outlined in https://github.com/Aaronius/penpal/pull/28#issuecomment-469872375, though. I'm still thinking that through.