From 7eb66942430b8852459298870ed8aecac0575b3a Mon Sep 17 00:00:00 2001 From: Daniel Brain Date: Wed, 20 Jul 2016 10:01:12 -0700 Subject: [PATCH] More robust bridge logic (ensure we use the same bridge for each pass-through call) --- src/compat/bridge.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/compat/bridge.js b/src/compat/bridge.js index 3c6efa8b..8618bd13 100644 --- a/src/compat/bridge.js +++ b/src/compat/bridge.js @@ -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;'); @@ -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;