-
Notifications
You must be signed in to change notification settings - Fork 56
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
Loading Penpal with System.js fails to connect #7
Comments
Then manually call:
|
After a small bit of thought, we actually removed the manual handshake from the function return and made it a more general part of the Penpal library. (We also realized that maybe we should be triggering on module load, not on iframe load, for the asynchronous module loading case.) I made a PR to that end: #8 |
Interesting. A couple thoughts that come to mind: (1) What if, instead of starting the handshake from the parent, we started it from the child. It's actually similar to what you're doing in your code, but rather than the child saying "hey parent, start the handshake", the child would be starting the handshake itself and waiting for the parent to acknowledge it. Maybe there's an obvious reason I'm missing as to why this wouldn't work. I need to look through the code to see what ramifications this would have. (2) If option 1 doesn't work for some reason, we could instead retry the handshake on an interval until a response is received from the child. Pros: It's resolved automatically. No need to send a message from the client, receive it from the parent, or call I can take a shot at implementation sometime. I would greatly prefer option 1. Thanks for reporting this issue. I do think it's something we should resolve. |
We both discussed. That makes a lot more sense. We'd prefer option 1 as well. 👍 |
That's a good thought, and it looks like the code supports that with one small problem (and it was already a problem for our thing too): what does the child use as the desired origin for the postMessage(HANDSHAKE call? Right now the only source of such information is a list of parentOrigins, but we're not allowed to pass in a list to postMessage. What my PR did was ask for a specific singular origin to use in the parameters of the reHandshakeWithParent function, but here we're inside of the connectToParent function which didn't take a specific singular origin. What should ParentOrigin become to support this usecase? Once that's resolved, I could finish modifying my PR to match that model instead simply enough. |
Yeah, you're right. We would probably need to limit That's too bad. I don't really have other ideas for handling that. How do you feel about running the handshake on an interval (option 2 from my last comment)? |
I don't love the interval idea. What I want to know is what the use case for having multiple parentOrigins is. I can think of a couple cases:
|
The use case is that a company like Johnson & Johnson has multiple sites like http://tylenol.com and http://sudafed.com and they each need to load http://jnj.com/coupon.html into an iframe and communicate with it. In this case, from http://jnj.com/coupon.html they would provide Penpal an array of origins that includes both http://tylenol.com and http://sudafed.com. Does that make sense? |
If the parent is always initializing the child, then you could do this sequence to still support child handshake:
Would that be an acceptable solution to both problems? |
It's an insecure approach. A nefarious website could pass an acceptable
origin through a get param and start communicating with the iframe.
…On Tue, Jul 18, 2017 at 10:24 PM Micah Gajewski ***@***.***> wrote:
If the parent is always initializing the child, then you could do this
sequence to still support child handshake:
1. Parent makes iframe with get param including the origin
2. Child checks if get param contains origin
3. Child checks if selected origin is in it's array of valid origins
4. Child sends handshake back to parent at selected origin.
Would that be an acceptable solution to both problems?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAM3hJtcwjvsJJWBc_ma6klEXQPn4DrMks5sPYTtgaJpZM4Obtth>
.
|
I spoke too soon. I don't think it will be insecure. I need to think about
potential problems with adding to the URL though. For example, it may mess
with consumers' analytics reporting. It may still be worth doing though.
…On Tue, Jul 18, 2017 at 10:34 PM Aaron Hardy ***@***.***> wrote:
It's an insecure approach. A nefarious website could pass an acceptable
origin through a get param and start communicating with the iframe.
On Tue, Jul 18, 2017 at 10:24 PM Micah Gajewski ***@***.***>
wrote:
> If the parent is always initializing the child, then you could do this
> sequence to still support child handshake:
>
> 1. Parent makes iframe with get param including the origin
> 2. Child checks if get param contains origin
> 3. Child checks if selected origin is in it's array of valid origins
> 4. Child sends handshake back to parent at selected origin.
>
> Would that be an acceptable solution to both problems?
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <#7 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AAM3hJtcwjvsJJWBc_ma6klEXQPn4DrMks5sPYTtgaJpZM4Obtth>
> .
>
|
Okay, rather than having the parent include the origin on a get param, the child should just be able to use Does this make sense to you? Feel free to give it a shot if you agree. |
Fixed in 2.6.0. The child now initiates the handshake. |
@gajewsk2 Did this work out okay for your system.js use case? |
System.js loads assets asynchronously (in development) and this causes the iframe's 'load' event to fire pre-emptively, for the purposes of Penpal. The child's connectToParent function has not been called, so it cannot receieve the message from the parent that is sent after the iframe's load event fires.
We have yet to find a way to cause System.js to load synchronously, except with bundling, which is only used in production. Currently we have developed a work-around that involves exposing a version of the handleIframeLoaded function that only calls the child.postMessage HANDSHAKE part of the function (which we have dubbed 'manualHandshake'). We then have the child send a message to the parent once System.js has done its work, to trigger a re-handshake.
The other solutions we tried, such as trying to re-fiore the Load event, didn't work because we are inside a situation where CORS is blocking us, which is what we wanted Penpal for in the first place.
Do you have any opinions or advice on how to address this issue without a code change to the repository? Alternately, we could submit a pull request with our solution if the solution sounds reasonable and useful. (Current 'issue' with the pull request is that it would change the return interface of connectToChild to return this extra handshaking function as well.)
The text was updated successfully, but these errors were encountered: