Skip to content

Commit

Permalink
More robust bridge logic (ensure we use the same bridge for each pass…
Browse files Browse the repository at this point in the history
…-through call)
  • Loading branch information
Daniel Brain committed Jul 20, 2016
1 parent d64bd51 commit 7eb6694
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/compat/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export let openBridge = util.memoize(url => {

let iframe = document.createElement('iframe');

iframe.setAttribute('name', id);
iframe.setAttribute('name', '__postrobot_bridge__');
iframe.setAttribute('id', id);

iframe.setAttribute('style', 'margin: 0; padding: 0; border: 0px none; overflow: hidden;');
Expand Down Expand Up @@ -62,11 +62,24 @@ export let openBridge = util.memoize(url => {
});

export function getBridge() {
return promise.Promise.resolve().then(() => bridge);
return promise.Promise.resolve().then(() => {
return bridge || getBridgeFor(window);
});
}

export function getBridgeFor(win) {

try {
let frame = win.frames.__postrobot_bridge__;

if (frame && frame !== window && isSameDomain(frame) && frame[CONSTANTS.WINDOW_PROPS.POSTROBOT]) {
return frame;
}

} catch (err) {
// pass
}

try {
if (!win || !win.frames || !win.frames.length) {
return;
Expand Down

0 comments on commit 7eb6694

Please # to comment.