Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRC-less iframes report ERR_NOT_IN_IFRAME #44

Closed
jameswragg opened this issue Apr 20, 2020 · 4 comments
Closed

SRC-less iframes report ERR_NOT_IN_IFRAME #44

jameswragg opened this issue Apr 20, 2020 · 4 comments

Comments

@jameswragg
Copy link

I'm creating an iframe with JS, building my own document (with Penpal in head) and writing it in, the iframe loads but Penpal fails with: connectToParent() must be called within an iframe when it actually is and the parent has Penpal running and listening.

The check that's failing is here: https://github.com/Aaronius/penpal/blob/master/src/connectToParent.js#L32

I can only assume window does equal window.top when the document has been built from the parent.

Here's a poor test-case on jsbin:
https://jsbin.com/huhocig/5/edit?html,js,output

Poor because jsbin uses iframes, so the condition is met but hopefully you'll get the gist of how I'm building my iframe.

Is there a way around this, or can the check be disabled? If I manually comment out the check - everything works as expected.

@jameswragg
Copy link
Author

I gave the iframe a generated name & it seemed to fix it!

@Aaronius
Copy link
Owner

Aaronius commented Apr 22, 2020

Thanks for the information @jameswragg. I'm glad you got it working. I tried to reproduce your example because I was curious about it, but things seem to be working for me. Here's my setup: http://dtm.aaronhardy.com/penpal/

Did I miss something?

@jameswragg
Copy link
Author

Thanks for coming back to me even though its working :)

The only difference is I'm creating the iframe & appending to the body, writing the contents in the onload callback but thats minimal difference & can only assume I was doing something silly as its working correctly now.

Using Penpal because I can apply it to any iframe, my goto for postmesaging (postmate) has to create the iframe itself. Glad I was forced to make the switch, really enjoying using it!

@Aaronius
Copy link
Owner

Thanks @jameswragg! I appreciate the kind words.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants