post-robot
Advanced tools
Comparing version 9.0.36 to 10.0.0
@@ -1,97 +0,104 @@ | ||
import 'zalgo-promise/src'; | ||
import { getParent, isWindowClosed } from 'cross-domain-utils/src'; | ||
import { noop, uniqueID } from 'belter/src'; | ||
"use strict"; | ||
import { MESSAGE_NAME, WILDCARD } from '../conf'; | ||
import { global, globalStore } from '../global'; | ||
exports.__esModule = true; | ||
exports.setupOpenTunnelToParent = setupOpenTunnelToParent; | ||
/* | ||
HERE BE DRAGONS | ||
var _src = require("cross-domain-utils/src"); | ||
Warning: this file may look weird. Why save the tunnel window in an Object | ||
by ID, then look it up later, rather than just using the reference from the closure scope? | ||
var _src2 = require("belter/src"); | ||
The reason is, that ends up meaning the garbage collector can never get its hands | ||
on a closed window, since our closure has continued access to it -- and post-robot | ||
has no good way to know whether to clean up the function with the closure scope. | ||
var _conf = require("../conf"); | ||
If you're editing this file, be sure to run significant memory / GC tests afterwards. | ||
*/ | ||
var _global = require("../global"); | ||
var tunnelWindows = globalStore('tunnelWindows'); | ||
function cleanTunnelWindows() { | ||
for (var _i2 = 0, _tunnelWindows$keys2 = tunnelWindows.keys(), _length2 = _tunnelWindows$keys2 == null ? 0 : _tunnelWindows$keys2.length; _i2 < _length2; _i2++) { | ||
var key = _tunnelWindows$keys2[_i2]; | ||
var tunnelWindow = tunnelWindows[key]; | ||
const tunnelWindows = (0, _global.globalStore)('tunnelWindows'); | ||
try { | ||
noop(tunnelWindow.source); | ||
} catch (err) { | ||
tunnelWindows.del(key); | ||
continue; | ||
} | ||
for (const key of tunnelWindows.keys()) { | ||
const tunnelWindow = tunnelWindows[key]; | ||
if (isWindowClosed(tunnelWindow.source)) { | ||
tunnelWindows.del(key); | ||
} | ||
try { | ||
(0, _src2.noop)(tunnelWindow.source); | ||
} catch (err) { | ||
tunnelWindows.del(key); | ||
continue; | ||
} | ||
if ((0, _src.isWindowClosed)(tunnelWindow.source)) { | ||
tunnelWindows.del(key); | ||
} | ||
} | ||
} | ||
function addTunnelWindow(_ref) { | ||
var name = _ref.name, | ||
source = _ref.source, | ||
canary = _ref.canary, | ||
sendMessage = _ref.sendMessage; | ||
cleanTunnelWindows(); | ||
var id = uniqueID(); | ||
tunnelWindows.set(id, { name: name, source: source, canary: canary, sendMessage: sendMessage }); | ||
return id; | ||
function addTunnelWindow({ | ||
name, | ||
source, | ||
canary, | ||
sendMessage | ||
}) { | ||
cleanTunnelWindows(); | ||
const id = (0, _src2.uniqueID)(); | ||
const tunnelWindows = (0, _global.globalStore)('tunnelWindows'); | ||
tunnelWindows.set(id, { | ||
name, | ||
source, | ||
canary, | ||
sendMessage | ||
}); | ||
return id; | ||
} | ||
global.openTunnelToParent = function openTunnelToParent(_ref2) { | ||
var name = _ref2.name, | ||
source = _ref2.source, | ||
canary = _ref2.canary, | ||
sendMessage = _ref2.sendMessage; | ||
function setupOpenTunnelToParent({ | ||
send | ||
}) { | ||
(0, _global.getGlobal)(window).openTunnelToParent = function openTunnelToParent({ | ||
name, | ||
source, | ||
canary, | ||
sendMessage | ||
}) { | ||
const tunnelWindows = (0, _global.globalStore)('tunnelWindows'); | ||
const parentWindow = (0, _src.getParent)(window); | ||
var parentWindow = getParent(window); | ||
if (!parentWindow) { | ||
throw new Error('No parent window found to open tunnel to'); | ||
throw new Error(`No parent window found to open tunnel to`); | ||
} | ||
var id = addTunnelWindow({ name: name, source: source, canary: canary, sendMessage: sendMessage }); | ||
const id = addTunnelWindow({ | ||
name, | ||
source, | ||
canary, | ||
sendMessage | ||
}); | ||
return send(parentWindow, _conf.MESSAGE_NAME.OPEN_TUNNEL, { | ||
name, | ||
return global.send(parentWindow, MESSAGE_NAME.OPEN_TUNNEL, { | ||
sendMessage() { | ||
const tunnelWindow = tunnelWindows.get(id); | ||
name: name, | ||
try { | ||
// IE gets antsy if you try to even reference a closed window | ||
(0, _src2.noop)(tunnelWindow && tunnelWindow.source); | ||
} catch (err) { | ||
tunnelWindows.del(id); | ||
return; | ||
} | ||
sendMessage: function sendMessage() { | ||
if (!tunnelWindow || !tunnelWindow.source || (0, _src.isWindowClosed)(tunnelWindow.source)) { | ||
return; | ||
} | ||
var tunnelWindow = tunnelWindows.get(id); | ||
try { | ||
tunnelWindow.canary(); | ||
} catch (err) { | ||
return; | ||
} | ||
try { | ||
// IE gets antsy if you try to even reference a closed window | ||
noop(tunnelWindow && tunnelWindow.source); | ||
} catch (err) { | ||
tunnelWindows.del(id); | ||
return; | ||
} | ||
tunnelWindow.sendMessage.apply(this, arguments); | ||
} | ||
if (!tunnelWindow || !tunnelWindow.source || isWindowClosed(tunnelWindow.source)) { | ||
return; | ||
} | ||
try { | ||
tunnelWindow.canary(); | ||
} catch (err) { | ||
return; | ||
} | ||
tunnelWindow.sendMessage.apply(this, arguments); | ||
} | ||
}, { domain: WILDCARD }); | ||
}; | ||
}, { | ||
domain: _conf.WILDCARD | ||
}); | ||
}; | ||
} |
@@ -1,123 +0,125 @@ | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { isSameDomain, getOpener, getDomain, getFrameByName } from 'cross-domain-utils/src'; | ||
import { weakMapMemoize, noop } from 'belter/src'; | ||
"use strict"; | ||
import { WINDOW_PROP } from '../conf'; | ||
import { global } from '../global'; | ||
exports.__esModule = true; | ||
exports.openTunnelToOpener = openTunnelToOpener; | ||
import { needsBridge, registerRemoteWindow, rejectRemoteSendMessage, registerRemoteSendMessage, getBridgeName } from './common'; | ||
var _src = require("zalgo-promise/src"); | ||
var awaitRemoteBridgeForWindow = weakMapMemoize(function (win) { | ||
return ZalgoPromise['try'](function () { | ||
try { | ||
var frame = getFrameByName(win, getBridgeName(getDomain())); | ||
var _src2 = require("cross-domain-utils/src"); | ||
if (!frame) { | ||
return; | ||
} | ||
var _src3 = require("belter/src"); | ||
// $FlowFixMe | ||
if (isSameDomain(frame) && frame[WINDOW_PROP.POSTROBOT]) { | ||
return frame; | ||
} | ||
var _global = require("../global"); | ||
return new ZalgoPromise(function (resolve) { | ||
var _common = require("./common"); | ||
var interval = void 0; | ||
var timeout = void 0; | ||
function awaitRemoteBridgeForWindow(win) { | ||
return (0, _global.windowStore)('remoteBridgeAwaiters').getOrSet(win, () => { | ||
return _src.ZalgoPromise.try(() => { | ||
const frame = (0, _src2.getFrameByName)(win, (0, _common.getBridgeName)((0, _src2.getDomain)())); | ||
interval = setInterval(function () { | ||
// $FlowFixMe | ||
if (frame && isSameDomain(frame) && frame[WINDOW_PROP.POSTROBOT]) { | ||
clearInterval(interval); | ||
clearTimeout(timeout); | ||
return resolve(frame); | ||
} | ||
}, 100); | ||
if (!frame) { | ||
throw new Error(`Bridge not found for domain: ${(0, _src2.getDomain)()}`); | ||
} // $FlowFixMe | ||
timeout = setTimeout(function () { | ||
clearInterval(interval); | ||
return resolve(); | ||
}, 2000); | ||
}); | ||
} catch (err) { | ||
// pass | ||
} | ||
}); | ||
}); | ||
export function openTunnelToOpener() { | ||
return ZalgoPromise['try'](function () { | ||
if ((0, _src2.isSameDomain)(frame) && (0, _global.getGlobal)(frame)) { | ||
return frame; | ||
} | ||
var opener = getOpener(window); | ||
return new _src.ZalgoPromise((resolve, reject) => { | ||
let interval; | ||
let timeout; // eslint-disable-line prefer-const | ||
if (!opener) { | ||
return; | ||
} | ||
interval = setInterval(() => { | ||
// eslint-disable-line prefer-const | ||
// $FlowFixMe | ||
if (frame && (0, _src2.isSameDomain)(frame) && (0, _global.getGlobal)(frame)) { | ||
clearInterval(interval); | ||
clearTimeout(timeout); | ||
return resolve(frame); | ||
} | ||
}, 100); | ||
timeout = setTimeout(() => { | ||
clearInterval(interval); | ||
return reject(new Error(`Bridge not found for domain: ${(0, _src2.getDomain)()}`)); | ||
}, 2000); | ||
}); | ||
}); | ||
}); | ||
} | ||
if (!needsBridge({ win: opener })) { | ||
return; | ||
} | ||
function openTunnelToOpener({ | ||
on, | ||
send, | ||
receiveMessage | ||
}) { | ||
return _src.ZalgoPromise.try(() => { | ||
const opener = (0, _src2.getOpener)(window); | ||
registerRemoteWindow(opener); | ||
if (!opener) { | ||
return; | ||
} | ||
return awaitRemoteBridgeForWindow(opener).then(function (bridge) { | ||
if (!(0, _common.needsBridge)({ | ||
win: opener | ||
})) { | ||
return; | ||
} | ||
if (!bridge) { | ||
return rejectRemoteSendMessage(opener, new Error('Can not register with opener: no bridge found in opener')); | ||
} | ||
(0, _common.registerRemoteWindow)(opener); | ||
return awaitRemoteBridgeForWindow(opener).then(bridge => { | ||
if (!window.name) { | ||
return (0, _common.rejectRemoteSendMessage)(opener, new Error(`Can not register with opener: window does not have a name`)); | ||
} // $FlowFixMe | ||
if (!window.name) { | ||
return rejectRemoteSendMessage(opener, new Error('Can not register with opener: window does not have a name')); | ||
} | ||
return bridge[WINDOW_PROP.POSTROBOT].openTunnelToParent({ | ||
return (0, _global.getGlobal)(bridge).openTunnelToParent({ | ||
name: window.name, | ||
source: window, | ||
name: window.name, | ||
canary() {// pass | ||
}, | ||
source: window, | ||
sendMessage(message) { | ||
try { | ||
(0, _src3.noop)(window); | ||
} catch (err) { | ||
return; | ||
} | ||
canary: function canary() { | ||
// pass | ||
}, | ||
sendMessage: function sendMessage(message) { | ||
if (!window || window.closed) { | ||
return; | ||
} | ||
try { | ||
noop(window); | ||
} catch (err) { | ||
return; | ||
} | ||
try { | ||
receiveMessage({ | ||
data: message, | ||
origin: this.origin, | ||
source: this.source | ||
}, { | ||
on, | ||
send | ||
}); | ||
} catch (err) { | ||
_src.ZalgoPromise.reject(err); | ||
} | ||
} | ||
if (!window || window.closed) { | ||
return; | ||
} | ||
}).then(({ | ||
source, | ||
origin, | ||
data | ||
}) => { | ||
if (source !== opener) { | ||
throw new Error(`Source does not match opener`); | ||
} | ||
try { | ||
global.receiveMessage({ | ||
data: message, | ||
origin: this.origin, | ||
source: this.source | ||
}); | ||
} catch (err) { | ||
ZalgoPromise.reject(err); | ||
} | ||
} | ||
}).then(function (_ref) { | ||
var source = _ref.source, | ||
origin = _ref.origin, | ||
data = _ref.data; | ||
if (source !== opener) { | ||
throw new Error('Source does not match opener'); | ||
} | ||
registerRemoteSendMessage(source, origin, data.sendMessage); | ||
})['catch'](function (err) { | ||
rejectRemoteSendMessage(opener, err); | ||
throw err; | ||
}); | ||
}); | ||
(0, _common.registerRemoteSendMessage)(source, origin, data.sendMessage); | ||
}).catch(err => { | ||
(0, _common.rejectRemoteSendMessage)(opener, err); | ||
throw err; | ||
}); | ||
}); | ||
}); | ||
} |
@@ -1,140 +0,148 @@ | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { getDomain, isSameDomain, isOpener, isSameTopWindow, matchDomain, getUserAgent, getDomainFromUrl } from 'cross-domain-utils/src'; | ||
import { noop } from 'belter/src'; | ||
"use strict"; | ||
import { BRIDGE_NAME_PREFIX } from '../conf'; | ||
import { windowStore } from '../global'; | ||
exports.__esModule = true; | ||
exports.needsBridgeForBrowser = needsBridgeForBrowser; | ||
exports.needsBridgeForWin = needsBridgeForWin; | ||
exports.needsBridgeForDomain = needsBridgeForDomain; | ||
exports.needsBridge = needsBridge; | ||
exports.getBridgeName = getBridgeName; | ||
exports.isBridge = isBridge; | ||
exports.registerRemoteWindow = registerRemoteWindow; | ||
exports.findRemoteWindow = findRemoteWindow; | ||
exports.registerRemoteSendMessage = registerRemoteSendMessage; | ||
exports.rejectRemoteSendMessage = rejectRemoteSendMessage; | ||
exports.sendBridgeMessage = sendBridgeMessage; | ||
exports.documentBodyReady = void 0; | ||
export function needsBridgeForBrowser() { | ||
var _src = require("zalgo-promise/src"); | ||
if (getUserAgent(window).match(/MSIE|trident|edge\/12|edge\/13/i)) { | ||
return true; | ||
} | ||
var _src2 = require("cross-domain-utils/src"); | ||
return false; | ||
} | ||
var _src3 = require("belter/src"); | ||
export function needsBridgeForWin(win) { | ||
var _conf = require("../conf"); | ||
if (!isSameTopWindow(window, win)) { | ||
return true; | ||
} | ||
var _global = require("../global"); | ||
return false; | ||
function needsBridgeForBrowser() { | ||
if ((0, _src2.getUserAgent)(window).match(/MSIE|trident|edge\/12|edge\/13/i)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
export function needsBridgeForDomain(domain, win) { | ||
function needsBridgeForWin(win) { | ||
if (!(0, _src2.isSameTopWindow)(window, win)) { | ||
return true; | ||
} | ||
if (domain) { | ||
if (getDomain() !== getDomainFromUrl(domain)) { | ||
return true; | ||
} | ||
} else if (win) { | ||
if (!isSameDomain(win)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return false; | ||
} | ||
export function needsBridge(_ref) { | ||
var win = _ref.win, | ||
domain = _ref.domain; | ||
if (!needsBridgeForBrowser()) { | ||
return false; | ||
function needsBridgeForDomain(domain, win) { | ||
if (domain) { | ||
if ((0, _src2.getDomain)() !== (0, _src2.getDomainFromUrl)(domain)) { | ||
return true; | ||
} | ||
if (domain && !needsBridgeForDomain(domain, win)) { | ||
return false; | ||
} else if (win) { | ||
if (!(0, _src2.isSameDomain)(win)) { | ||
return true; | ||
} | ||
} | ||
if (win && !needsBridgeForWin(win)) { | ||
return false; | ||
} | ||
return true; | ||
return false; | ||
} | ||
export function getBridgeName(domain) { | ||
function needsBridge({ | ||
win, | ||
domain | ||
}) { | ||
if (!needsBridgeForBrowser()) { | ||
return false; | ||
} | ||
domain = domain || getDomainFromUrl(domain); | ||
if (domain && !needsBridgeForDomain(domain, win)) { | ||
return false; | ||
} | ||
var sanitizedDomain = domain.replace(/[^a-zA-Z0-9]+/g, '_'); | ||
if (win && !needsBridgeForWin(win)) { | ||
return false; | ||
} | ||
var id = BRIDGE_NAME_PREFIX + '_' + sanitizedDomain; | ||
return true; | ||
} | ||
return id; | ||
function getBridgeName(domain) { | ||
domain = domain || (0, _src2.getDomainFromUrl)(domain); | ||
const sanitizedDomain = domain.replace(/[^a-zA-Z0-9]+/g, '_'); | ||
const id = `${_conf.BRIDGE_NAME_PREFIX}_${sanitizedDomain}`; | ||
return id; | ||
} | ||
export function isBridge() { | ||
return Boolean(window.name && window.name === getBridgeName(getDomain())); | ||
function isBridge() { | ||
return Boolean(window.name && window.name === getBridgeName((0, _src2.getDomain)())); | ||
} | ||
export var documentBodyReady = new ZalgoPromise(function (resolve) { | ||
const documentBodyReady = new _src.ZalgoPromise(resolve => { | ||
if (window.document && window.document.body) { | ||
return resolve(window.document.body); | ||
} | ||
const interval = setInterval(() => { | ||
if (window.document && window.document.body) { | ||
return resolve(window.document.body); | ||
clearInterval(interval); | ||
return resolve(window.document.body); | ||
} | ||
var interval = setInterval(function () { | ||
if (window.document && window.document.body) { | ||
clearInterval(interval); | ||
return resolve(window.document.body); | ||
} | ||
}, 10); | ||
}, 10); | ||
}); | ||
exports.documentBodyReady = documentBodyReady; | ||
var remoteWindows = windowStore('remoteWindows'); | ||
export function registerRemoteWindow(win) { | ||
remoteWindows.getOrSet(win, function () { | ||
return new ZalgoPromise(); | ||
}); | ||
function registerRemoteWindow(win) { | ||
const remoteWindowPromises = (0, _global.windowStore)('remoteWindowPromises'); | ||
remoteWindowPromises.getOrSet(win, () => new _src.ZalgoPromise()); | ||
} | ||
export function findRemoteWindow(win) { | ||
var remoteWin = remoteWindows.get(win); | ||
function findRemoteWindow(win) { | ||
const remoteWindowPromises = (0, _global.windowStore)('remoteWindowPromises'); | ||
const remoteWinPromise = remoteWindowPromises.get(win); | ||
if (!remoteWin) { | ||
throw new Error('Remote window not found'); | ||
} | ||
if (!remoteWinPromise) { | ||
throw new Error(`Remote window promise not found`); | ||
} | ||
return remoteWin; | ||
return remoteWinPromise; | ||
} | ||
export function registerRemoteSendMessage(win, domain, sendMessage) { | ||
var sendMessageWrapper = function sendMessageWrapper(remoteWin, remoteDomain, message) { | ||
if (remoteWin !== win) { | ||
throw new Error('Remote window does not match window'); | ||
} | ||
function registerRemoteSendMessage(win, domain, sendMessage) { | ||
const sendMessageWrapper = (remoteWin, remoteDomain, message) => { | ||
if (remoteWin !== win) { | ||
throw new Error(`Remote window does not match window`); | ||
} | ||
if (!matchDomain(remoteDomain, domain)) { | ||
throw new Error('Remote domain ' + remoteDomain + ' does not match domain ' + domain); | ||
} | ||
if (!(0, _src2.matchDomain)(remoteDomain, domain)) { | ||
throw new Error(`Remote domain ${remoteDomain} does not match domain ${domain}`); | ||
} | ||
sendMessage(message); | ||
}; | ||
sendMessage.fireAndForget(message); | ||
}; | ||
findRemoteWindow(win).resolve(sendMessageWrapper); | ||
findRemoteWindow(win).resolve(sendMessageWrapper); | ||
} | ||
export function rejectRemoteSendMessage(win, err) { | ||
findRemoteWindow(win).reject(err)['catch'](noop); | ||
function rejectRemoteSendMessage(win, err) { | ||
findRemoteWindow(win).reject(err).catch(_src3.noop); | ||
} | ||
export function sendBridgeMessage(win, domain, message) { | ||
function sendBridgeMessage(win, domain, message) { | ||
const messagingChild = (0, _src2.isOpener)(window, win); | ||
const messagingParent = (0, _src2.isOpener)(win, window); | ||
var messagingChild = isOpener(window, win); | ||
var messagingParent = isOpener(win, window); | ||
if (!messagingChild && !messagingParent) { | ||
throw new Error(`Can only send messages to and from parent and popup windows`); | ||
} | ||
if (!messagingChild && !messagingParent) { | ||
throw new Error('Can only send messages to and from parent and popup windows'); | ||
} | ||
return findRemoteWindow(win).then(function (sendMessage) { | ||
return sendMessage(win, domain, message); | ||
}); | ||
return findRemoteWindow(win).then(sendMessage => { | ||
return sendMessage(win, domain, message); | ||
}); | ||
} |
@@ -0,8 +1,38 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
// eslint-disable-next-line import/no-unassigned-import | ||
import './bridge'; | ||
var _bridge = require("./bridge"); | ||
export * from './child'; | ||
export * from './common'; | ||
export * from './parent'; | ||
Object.keys(_bridge).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _bridge[key]; | ||
}); | ||
var _child = require("./child"); | ||
Object.keys(_child).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _child[key]; | ||
}); | ||
var _common = require("./common"); | ||
Object.keys(_common).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _common[key]; | ||
}); | ||
var _parent = require("./parent"); | ||
Object.keys(_parent).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _parent[key]; | ||
}); | ||
var _setup = require("./setup"); | ||
Object.keys(_setup).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _setup[key]; | ||
}); |
@@ -1,224 +0,251 @@ | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { getDomain, getFrameByName, isWindowClosed, getDomainFromUrl, normalizeMockUrl } from 'cross-domain-utils/src'; | ||
"use strict"; | ||
import { CONFIG, MESSAGE_NAME } from '../conf'; | ||
import { awaitWindowHello } from '../lib'; | ||
import { global, windowStore, globalStore } from '../global'; | ||
exports.__esModule = true; | ||
exports.listenForOpenTunnel = listenForOpenTunnel; | ||
exports.hasBridge = hasBridge; | ||
exports.openBridge = openBridge; | ||
exports.linkWindow = linkWindow; | ||
exports.linkUrl = linkUrl; | ||
exports.listenForWindowOpen = listenForWindowOpen; | ||
exports.destroyBridges = destroyBridges; | ||
import { getBridgeName, documentBodyReady, registerRemoteSendMessage, registerRemoteWindow } from './common'; | ||
var _src = require("zalgo-promise/src"); | ||
var bridges = globalStore('bridges'); | ||
var bridgeFrames = globalStore('bridgeFrames'); | ||
var popupWindowsByName = globalStore('popupWindowsByName'); | ||
var popupWindowsByWin = windowStore('popupWindowsByWin'); | ||
var _src2 = require("cross-domain-utils/src"); | ||
function listenForRegister(source, domain) { | ||
global.on(MESSAGE_NAME.OPEN_TUNNEL, { window: source, domain: domain }, function (_ref) { | ||
var origin = _ref.origin, | ||
data = _ref.data; | ||
var _conf = require("../conf"); | ||
var _lib = require("../lib"); | ||
if (origin !== domain) { | ||
throw new Error('Domain ' + domain + ' does not match origin ' + origin); | ||
} | ||
var _global = require("../global"); | ||
if (!data.name) { | ||
throw new Error('Register window expected to be passed window name'); | ||
} | ||
var _common = require("./common"); | ||
if (!data.sendMessage) { | ||
throw new Error('Register window expected to be passed sendMessage method'); | ||
} | ||
function listenForOpenTunnel({ | ||
on, | ||
send, | ||
receiveMessage | ||
}) { | ||
const popupWindowsByName = (0, _global.globalStore)('popupWindowsByName'); | ||
on(_conf.MESSAGE_NAME.OPEN_TUNNEL, ({ | ||
source, | ||
origin, | ||
data | ||
}) => { | ||
const bridgePromise = (0, _global.globalStore)('bridges').get(origin); | ||
if (!popupWindowsByName.has(data.name)) { | ||
throw new Error('Window with name ' + data.name + ' does not exist, or was not opened by this window'); | ||
} | ||
if (!bridgePromise) { | ||
throw new Error(`Can not find bridge promise for domain ${origin}`); | ||
} | ||
return bridgePromise.then(bridge => { | ||
// $FlowFixMe | ||
if (source !== bridge) { | ||
// $FlowFixMe | ||
if (!popupWindowsByName.get(data.name).domain) { | ||
throw new Error('We do not have a registered domain for window ' + data.name); | ||
} | ||
throw new Error(`Message source does not matched registered bridge for domain ${origin}`); | ||
} | ||
// $FlowFixMe | ||
if (popupWindowsByName.get(data.name).domain !== origin) { | ||
// $FlowFixMe | ||
throw new Error('Message origin ' + origin + ' does not matched registered window origin ' + popupWindowsByName.get(data.name).domain); | ||
} | ||
if (!data.name) { | ||
throw new Error(`Register window expected to be passed window name`); | ||
} | ||
// $FlowFixMe | ||
registerRemoteSendMessage(popupWindowsByName.get(data.name).win, domain, data.sendMessage); | ||
if (!data.sendMessage) { | ||
throw new Error(`Register window expected to be passed sendMessage method`); | ||
} | ||
return { | ||
sendMessage: function sendMessage(message) { | ||
if (!popupWindowsByName.has(data.name)) { | ||
throw new Error(`Window with name ${data.name} does not exist, or was not opened by this window`); | ||
} // $FlowFixMe | ||
if (!window || window.closed) { | ||
return; | ||
} | ||
var winDetails = popupWindowsByName.get(data.name); | ||
if (!popupWindowsByName.get(data.name).domain) { | ||
throw new Error(`We do not have a registered domain for window ${data.name}`); | ||
} // $FlowFixMe | ||
if (!winDetails) { | ||
return; | ||
} | ||
try { | ||
global.receiveMessage({ | ||
data: message, | ||
origin: winDetails.domain, | ||
source: winDetails.win | ||
}); | ||
} catch (err) { | ||
ZalgoPromise.reject(err); | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
if (popupWindowsByName.get(data.name).domain !== origin) { | ||
// $FlowFixMe | ||
throw new Error(`Message origin ${origin} does not matched registered window origin ${popupWindowsByName.get(data.name).domain}`); | ||
} // $FlowFixMe | ||
function openBridgeFrame(name, url) { | ||
var iframe = document.createElement('iframe'); | ||
(0, _common.registerRemoteSendMessage)(popupWindowsByName.get(data.name).win, origin, data.sendMessage); | ||
return { | ||
sendMessage(message) { | ||
if (!window || window.closed) { | ||
return; | ||
} | ||
iframe.setAttribute('name', name); | ||
iframe.setAttribute('id', name); | ||
const winDetails = popupWindowsByName.get(data.name); | ||
iframe.setAttribute('style', 'display: none; margin: 0; padding: 0; border: 0px none; overflow: hidden;'); | ||
iframe.setAttribute('frameborder', '0'); | ||
iframe.setAttribute('border', '0'); | ||
iframe.setAttribute('scrolling', 'no'); | ||
iframe.setAttribute('allowTransparency', 'true'); | ||
if (!winDetails) { | ||
return; | ||
} | ||
iframe.setAttribute('tabindex', '-1'); | ||
iframe.setAttribute('hidden', 'true'); | ||
iframe.setAttribute('title', ''); | ||
iframe.setAttribute('role', 'presentation'); | ||
try { | ||
receiveMessage({ | ||
data: message, | ||
origin: winDetails.domain, | ||
source: winDetails.win | ||
}, { | ||
on, | ||
send | ||
}); | ||
} catch (err) { | ||
_src.ZalgoPromise.reject(err); | ||
} | ||
} | ||
iframe.src = url; | ||
}; | ||
}); | ||
}); | ||
} | ||
return iframe; | ||
function openBridgeFrame(name, url) { | ||
const iframe = document.createElement(`iframe`); | ||
iframe.setAttribute(`name`, name); | ||
iframe.setAttribute(`id`, name); | ||
iframe.setAttribute(`style`, `display: none; margin: 0; padding: 0; border: 0px none; overflow: hidden;`); | ||
iframe.setAttribute(`frameborder`, `0`); | ||
iframe.setAttribute(`border`, `0`); | ||
iframe.setAttribute(`scrolling`, `no`); | ||
iframe.setAttribute(`allowTransparency`, `true`); | ||
iframe.setAttribute(`tabindex`, `-1`); | ||
iframe.setAttribute(`hidden`, `true`); | ||
iframe.setAttribute(`title`, ``); | ||
iframe.setAttribute(`role`, `presentation`); | ||
iframe.src = url; | ||
return iframe; | ||
} | ||
export function hasBridge(url, domain) { | ||
return bridges.has(domain || getDomainFromUrl(url)); | ||
function hasBridge(url, domain) { | ||
const bridges = (0, _global.globalStore)('bridges'); | ||
return bridges.has(domain || (0, _src2.getDomainFromUrl)(url)); | ||
} | ||
export function openBridge(url, domain) { | ||
domain = domain || getDomainFromUrl(url); | ||
function openBridge(url, domain) { | ||
const bridges = (0, _global.globalStore)('bridges'); | ||
const bridgeFrames = (0, _global.globalStore)('bridgeFrames'); | ||
domain = domain || (0, _src2.getDomainFromUrl)(url); | ||
return bridges.getOrSet(domain, () => _src.ZalgoPromise.try(() => { | ||
if ((0, _src2.getDomain)() === domain) { | ||
throw new Error(`Can not open bridge on the same domain as current domain: ${domain}`); | ||
} | ||
return bridges.getOrSet(domain, function () { | ||
return ZalgoPromise['try'](function () { | ||
const name = (0, _common.getBridgeName)(domain); | ||
const frame = (0, _src2.getFrameByName)(window, name); | ||
if (getDomain() === domain) { | ||
throw new Error('Can not open bridge on the same domain as current domain: ' + domain); | ||
} | ||
if (frame) { | ||
throw new Error(`Frame with name ${name} already exists on page`); | ||
} | ||
var name = getBridgeName(domain); | ||
var frame = getFrameByName(window, name); | ||
if (frame) { | ||
throw new Error('Frame with name ' + name + ' already exists on page'); | ||
} | ||
var iframe = openBridgeFrame(name, url); | ||
bridgeFrames.set(domain, iframe); | ||
return documentBodyReady.then(function (body) { | ||
body.appendChild(iframe); | ||
var bridge = iframe.contentWindow; | ||
listenForRegister(bridge, domain); | ||
return new ZalgoPromise(function (resolve, reject) { | ||
iframe.onload = resolve; | ||
iframe.onerror = reject; | ||
}).then(function () { | ||
return awaitWindowHello(bridge, CONFIG.BRIDGE_TIMEOUT, 'Bridge ' + url); | ||
}).then(function () { | ||
return bridge; | ||
}); | ||
}); | ||
}); | ||
const iframe = openBridgeFrame(name, url); | ||
bridgeFrames.set(domain, iframe); | ||
return _common.documentBodyReady.then(body => { | ||
body.appendChild(iframe); | ||
const bridge = iframe.contentWindow; | ||
return new _src.ZalgoPromise((resolve, reject) => { | ||
iframe.addEventListener('load', resolve); | ||
iframe.addEventListener('error', reject); | ||
}).then(() => { | ||
return (0, _lib.awaitWindowHello)(bridge, _conf.BRIDGE_TIMEOUT, `Bridge ${url}`); | ||
}).then(() => { | ||
return bridge; | ||
}); | ||
}); | ||
})); | ||
} | ||
export function linkWindow(_ref2) { | ||
var win = _ref2.win, | ||
name = _ref2.name, | ||
domain = _ref2.domain; | ||
function linkWindow({ | ||
win, | ||
name, | ||
domain | ||
}) { | ||
const popupWindowsByName = (0, _global.globalStore)('popupWindowsByName'); | ||
const popupWindowsByWin = (0, _global.windowStore)('popupWindowsByWin'); | ||
for (var _i2 = 0, _popupWindowsByName$k2 = popupWindowsByName.keys(), _length2 = _popupWindowsByName$k2 == null ? 0 : _popupWindowsByName$k2.length; _i2 < _length2; _i2++) { | ||
var winName = _popupWindowsByName$k2[_i2]; | ||
// $FlowFixMe | ||
if (isWindowClosed(popupWindowsByName.get(winName).win)) { | ||
popupWindowsByName.del(winName); | ||
} | ||
for (const winName of popupWindowsByName.keys()) { | ||
// $FlowFixMe | ||
if ((0, _src2.isWindowClosed)(popupWindowsByName.get(winName).win)) { | ||
popupWindowsByName.del(winName); | ||
} | ||
} | ||
var details = popupWindowsByWin.getOrSet(win, function () { | ||
if (!name) { | ||
return { win: win }; | ||
} | ||
const details = popupWindowsByWin.getOrSet(win, () => { | ||
if (!name) { | ||
return { | ||
win | ||
}; | ||
} | ||
return popupWindowsByName.getOrSet(name, function () { | ||
return { win: win, name: name }; | ||
}); | ||
return popupWindowsByName.getOrSet(name, () => { | ||
return { | ||
win, | ||
name | ||
}; | ||
}); | ||
}); | ||
if (details.win && details.win !== win) { | ||
throw new Error('Different window already linked for window: ' + (name || 'undefined')); | ||
} | ||
if (details.win && details.win !== win) { | ||
throw new Error(`Different window already linked for window: ${name || 'undefined'}`); | ||
} | ||
if (name) { | ||
if (details.name && details.name !== name) { | ||
throw new Error('Different window already linked for name ' + name + ': ' + details.name); | ||
} | ||
details.name = name; | ||
popupWindowsByName.set(name, details); | ||
if (name) { | ||
if (details.name && details.name !== name) { | ||
throw new Error(`Different window already linked for name ${name}: ${details.name}`); | ||
} | ||
if (domain) { | ||
details.domain = domain; | ||
registerRemoteWindow(win); | ||
} | ||
details.name = name; | ||
popupWindowsByName.set(name, details); | ||
} | ||
popupWindowsByWin.set(win, details); | ||
if (domain) { | ||
details.domain = domain; | ||
(0, _common.registerRemoteWindow)(win); | ||
} | ||
return details; | ||
popupWindowsByWin.set(win, details); | ||
return details; | ||
} | ||
export function linkUrl(win, url) { | ||
linkWindow({ win: win, domain: getDomainFromUrl(url) }); | ||
function linkUrl(win, url) { | ||
linkWindow({ | ||
win, | ||
domain: (0, _src2.getDomainFromUrl)(url) | ||
}); | ||
} | ||
var windowOpen = window.open; | ||
function listenForWindowOpen() { | ||
const windowOpen = window.open; | ||
window.open = function windowOpenWrapper(url, name, options, last) { | ||
var win = windowOpen.call(this, normalizeMockUrl(url), name, options, last); | ||
window.open = function windowOpenWrapper(url, name, options, last) { | ||
const win = windowOpen.call(this, (0, _src2.normalizeMockUrl)(url), name, options, last); | ||
if (!win) { | ||
return win; | ||
return win; | ||
} | ||
linkWindow({ win: win, name: name, domain: url ? getDomainFromUrl(url) : null }); | ||
linkWindow({ | ||
win, | ||
name, | ||
domain: url ? (0, _src2.getDomainFromUrl)(url) : null | ||
}); | ||
return win; | ||
}; | ||
}; | ||
} | ||
export function destroyBridges() { | ||
for (var _i4 = 0, _bridgeFrames$keys2 = bridgeFrames.keys(), _length4 = _bridgeFrames$keys2 == null ? 0 : _bridgeFrames$keys2.length; _i4 < _length4; _i4++) { | ||
var _domain = _bridgeFrames$keys2[_i4]; | ||
var frame = bridgeFrames.get(_domain); | ||
if (frame && frame.parentNode) { | ||
frame.parentNode.removeChild(frame); | ||
} | ||
function destroyBridges() { | ||
const bridges = (0, _global.globalStore)('bridges'); | ||
const bridgeFrames = (0, _global.globalStore)('bridgeFrames'); | ||
for (const domain of bridgeFrames.keys()) { | ||
const frame = bridgeFrames.get(domain); | ||
if (frame && frame.parentNode) { | ||
frame.parentNode.removeChild(frame); | ||
} | ||
} | ||
bridgeFrames.reset(); | ||
bridges.reset(); | ||
bridgeFrames.reset(); | ||
bridges.reset(); | ||
} |
@@ -1,11 +0,16 @@ | ||
import 'cross-domain-utils/src'; | ||
import { noop } from 'belter/src'; | ||
"use strict"; | ||
import { requestPromises } from './public'; | ||
exports.__esModule = true; | ||
exports.cleanUpWindow = cleanUpWindow; | ||
export function cleanUpWindow(win) { | ||
for (var _i2 = 0, _requestPromises$get2 = requestPromises.get(win, []), _length2 = _requestPromises$get2 == null ? 0 : _requestPromises$get2.length; _i2 < _length2; _i2++) { | ||
var promise = _requestPromises$get2[_i2]; | ||
promise.reject(new Error('Window cleaned up before response'))['catch'](noop); | ||
} | ||
var _src = require("belter/src"); | ||
var _global = require("./global"); | ||
function cleanUpWindow(win) { | ||
const requestPromises = (0, _global.windowStore)('requestPromises'); | ||
for (const promise of requestPromises.get(win, [])) { | ||
promise.reject(new Error(`Window cleaned up before response`)).catch(_src.noop); | ||
} | ||
} |
@@ -1,14 +0,14 @@ | ||
var _ALLOWED_POST_MESSAGE; | ||
"use strict"; | ||
import { SEND_STRATEGY } from './constants'; | ||
export var CONFIG = { | ||
BRIDGE_TIMEOUT: 5000, | ||
CHILD_WINDOW_TIMEOUT: 5000, | ||
ACK_TIMEOUT: 2000, | ||
ACK_TIMEOUT_KNOWN: 10000, | ||
RES_TIMEOUT: __TEST__ ? 2000 : -1, | ||
ALLOWED_POST_MESSAGE_METHODS: (_ALLOWED_POST_MESSAGE = {}, _ALLOWED_POST_MESSAGE[SEND_STRATEGY.POST_MESSAGE] = true, _ALLOWED_POST_MESSAGE[SEND_STRATEGY.BRIDGE] = true, _ALLOWED_POST_MESSAGE[SEND_STRATEGY.GLOBAL] = true, _ALLOWED_POST_MESSAGE) | ||
}; | ||
exports.__esModule = true; | ||
exports.RES_TIMEOUT = exports.ACK_TIMEOUT_KNOWN = exports.ACK_TIMEOUT = exports.CHILD_WINDOW_TIMEOUT = exports.BRIDGE_TIMEOUT = void 0; | ||
const BRIDGE_TIMEOUT = 5000; | ||
exports.BRIDGE_TIMEOUT = BRIDGE_TIMEOUT; | ||
const CHILD_WINDOW_TIMEOUT = 5000; | ||
exports.CHILD_WINDOW_TIMEOUT = CHILD_WINDOW_TIMEOUT; | ||
const ACK_TIMEOUT = 2000; | ||
exports.ACK_TIMEOUT = ACK_TIMEOUT; | ||
const ACK_TIMEOUT_KNOWN = 10000; | ||
exports.ACK_TIMEOUT_KNOWN = ACK_TIMEOUT_KNOWN; | ||
const RES_TIMEOUT = __TEST__ ? 2000 : -1; | ||
exports.RES_TIMEOUT = RES_TIMEOUT; |
@@ -1,42 +0,39 @@ | ||
export var MESSAGE_TYPE = { | ||
REQUEST: 'postrobot_message_request', | ||
RESPONSE: 'postrobot_message_response', | ||
ACK: 'postrobot_message_ack' | ||
}; | ||
"use strict"; | ||
export var MESSAGE_ACK = { | ||
SUCCESS: 'success', | ||
ERROR: 'error' | ||
exports.__esModule = true; | ||
exports.SERIALIZATION_TYPE = exports.WILDCARD = exports.POSTROBOT_PROXY = exports.BRIDGE_NAME_PREFIX = exports.SEND_STRATEGY = exports.MESSAGE_NAME = exports.MESSAGE_ACK = exports.MESSAGE_TYPE = void 0; | ||
const MESSAGE_TYPE = { | ||
REQUEST: 'postrobot_message_request', | ||
RESPONSE: 'postrobot_message_response', | ||
ACK: 'postrobot_message_ack' | ||
}; | ||
export var MESSAGE_NAME = { | ||
METHOD: 'postrobot_method', | ||
HELLO: 'postrobot_hello', | ||
OPEN_TUNNEL: 'postrobot_open_tunnel' | ||
exports.MESSAGE_TYPE = MESSAGE_TYPE; | ||
const MESSAGE_ACK = { | ||
SUCCESS: 'success', | ||
ERROR: 'error' | ||
}; | ||
export var WINDOW_PROP = { | ||
POSTROBOT: '__postRobot__' | ||
exports.MESSAGE_ACK = MESSAGE_ACK; | ||
const MESSAGE_NAME = { | ||
METHOD: 'postrobot_method', | ||
HELLO: 'postrobot_hello', | ||
OPEN_TUNNEL: 'postrobot_open_tunnel' | ||
}; | ||
export var SEND_STRATEGY = { | ||
POST_MESSAGE: 'postrobot_post_message', | ||
BRIDGE: 'postrobot_bridge', | ||
GLOBAL: 'postrobot_global' | ||
exports.MESSAGE_NAME = MESSAGE_NAME; | ||
const SEND_STRATEGY = { | ||
POST_MESSAGE: 'postrobot_post_message', | ||
BRIDGE: 'postrobot_bridge', | ||
GLOBAL: 'postrobot_global' | ||
}; | ||
export var PROTOCOL = { | ||
MOCK: 'mock:', | ||
FILE: 'file:' | ||
exports.SEND_STRATEGY = SEND_STRATEGY; | ||
const BRIDGE_NAME_PREFIX = '__postrobot_bridge__'; | ||
exports.BRIDGE_NAME_PREFIX = BRIDGE_NAME_PREFIX; | ||
const POSTROBOT_PROXY = '__postrobot_proxy__'; | ||
exports.POSTROBOT_PROXY = POSTROBOT_PROXY; | ||
const WILDCARD = '*'; | ||
exports.WILDCARD = WILDCARD; | ||
const SERIALIZATION_TYPE = { | ||
CROSS_DOMAIN_ZALGO_PROMISE: 'cross_domain_zalgo_promise', | ||
CROSS_DOMAIN_FUNCTION: 'cross_domain_function', | ||
CROSS_DOMAIN_WINDOW: 'cross_domain_window' | ||
}; | ||
export var BRIDGE_NAME_PREFIX = '__postrobot_bridge__'; | ||
export var POSTROBOT_PROXY = '__postrobot_proxy__'; | ||
export var WILDCARD = '*'; | ||
export var SERIALIZATION_TYPE = { | ||
CROSS_DOMAIN_ZALGO_PROMISE: 'cross_domain_zalgo_promise', | ||
CROSS_DOMAIN_FUNCTION: 'cross_domain_function', | ||
CROSS_DOMAIN_WINDOW: 'cross_domain_window' | ||
}; | ||
exports.SERIALIZATION_TYPE = SERIALIZATION_TYPE; |
@@ -1,2 +0,17 @@ | ||
export * from './config'; | ||
export * from './constants'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _config = require("./config"); | ||
Object.keys(_config).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _config[key]; | ||
}); | ||
var _constants = require("./constants"); | ||
Object.keys(_constants).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _constants[key]; | ||
}); |
@@ -1,3 +0,24 @@ | ||
export * from './receive'; | ||
export * from './send'; | ||
export * from './listeners'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _receive = require("./receive"); | ||
Object.keys(_receive).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _receive[key]; | ||
}); | ||
var _send = require("./send"); | ||
Object.keys(_send).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _send[key]; | ||
}); | ||
var _listeners = require("./listeners"); | ||
Object.keys(_listeners).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _listeners[key]; | ||
}); |
@@ -1,213 +0,235 @@ | ||
import 'zalgo-promise/src'; | ||
import { matchDomain } from 'cross-domain-utils/src'; | ||
import { isRegex, getOrSet } from 'belter/src'; | ||
"use strict"; | ||
import { global, globalStore, windowStore } from '../global'; | ||
import { WILDCARD } from '../conf'; | ||
exports.__esModule = true; | ||
exports.resetListeners = resetListeners; | ||
exports.addResponseListener = addResponseListener; | ||
exports.getResponseListener = getResponseListener; | ||
exports.deleteResponseListener = deleteResponseListener; | ||
exports.markResponseListenerErrored = markResponseListenerErrored; | ||
exports.isResponseListenerErrored = isResponseListenerErrored; | ||
exports.getRequestListener = getRequestListener; | ||
exports.addRequestListener = addRequestListener; | ||
var responseListeners = globalStore('responseListeners'); | ||
var requestListeners = windowStore('requestListeners'); | ||
var erroredResponseListeners = globalStore('erroredResponseListeners'); | ||
var _src = require("cross-domain-utils/src"); | ||
export function resetListeners() { | ||
responseListeners.reset(); | ||
erroredResponseListeners.reset(); | ||
} | ||
var _src2 = require("belter/src"); | ||
global.WINDOW_WILDCARD = global.WINDOW_WILDCARD || new function WindowWildcard() {/* pass */}(); | ||
var _global = require("../global"); | ||
var __DOMAIN_REGEX__ = '__domain_regex__'; | ||
var _conf = require("../conf"); | ||
export function addResponseListener(hash, listener) { | ||
responseListeners.set(hash, listener); | ||
function resetListeners() { | ||
const responseListeners = (0, _global.globalStore)('responseListeners'); | ||
const erroredResponseListeners = (0, _global.globalStore)('erroredResponseListeners'); | ||
responseListeners.reset(); | ||
erroredResponseListeners.reset(); | ||
} | ||
export function getResponseListener(hash) { | ||
return responseListeners.get(hash); | ||
const __DOMAIN_REGEX__ = '__domain_regex__'; | ||
function addResponseListener(hash, listener) { | ||
const responseListeners = (0, _global.globalStore)('responseListeners'); | ||
responseListeners.set(hash, listener); | ||
} | ||
export function deleteResponseListener(hash) { | ||
responseListeners.del(hash); | ||
function getResponseListener(hash) { | ||
const responseListeners = (0, _global.globalStore)('responseListeners'); | ||
return responseListeners.get(hash); | ||
} | ||
export function markResponseListenerErrored(hash) { | ||
erroredResponseListeners.set(hash, true); | ||
function deleteResponseListener(hash) { | ||
const responseListeners = (0, _global.globalStore)('responseListeners'); | ||
responseListeners.del(hash); | ||
} | ||
export function isResponseListenerErrored(hash) { | ||
return erroredResponseListeners.has(hash); | ||
function markResponseListenerErrored(hash) { | ||
const erroredResponseListeners = (0, _global.globalStore)('erroredResponseListeners'); | ||
erroredResponseListeners.set(hash, true); | ||
} | ||
export function getRequestListener(_ref) { | ||
var name = _ref.name, | ||
win = _ref.win, | ||
domain = _ref.domain; | ||
function isResponseListenerErrored(hash) { | ||
const erroredResponseListeners = (0, _global.globalStore)('erroredResponseListeners'); | ||
return erroredResponseListeners.has(hash); | ||
} | ||
function getRequestListener({ | ||
name, | ||
win, | ||
domain | ||
}) { | ||
const requestListeners = (0, _global.windowStore)('requestListeners'); | ||
if (win === WILDCARD) { | ||
win = null; | ||
} | ||
if (win === _conf.WILDCARD) { | ||
win = null; | ||
} | ||
if (domain === WILDCARD) { | ||
domain = null; | ||
} | ||
if (domain === _conf.WILDCARD) { | ||
domain = null; | ||
} | ||
if (!name) { | ||
throw new Error('Name required to get request listener'); | ||
if (!name) { | ||
throw new Error(`Name required to get request listener`); | ||
} | ||
for (const winQualifier of [win, (0, _global.getWildcard)()]) { | ||
if (!winQualifier) { | ||
continue; | ||
} | ||
for (var _i2 = 0, _ref3 = [win, global.WINDOW_WILDCARD], _length2 = _ref3 == null ? 0 : _ref3.length; _i2 < _length2; _i2++) { | ||
var winQualifier = _ref3[_i2]; | ||
if (!winQualifier) { | ||
continue; | ||
} | ||
const nameListeners = requestListeners.get(winQualifier); | ||
var nameListeners = requestListeners.get(winQualifier); | ||
if (!nameListeners) { | ||
continue; | ||
} | ||
if (!nameListeners) { | ||
continue; | ||
} | ||
const domainListeners = nameListeners[name]; | ||
var domainListeners = nameListeners[name]; | ||
if (!domainListeners) { | ||
continue; | ||
} | ||
if (!domainListeners) { | ||
continue; | ||
} | ||
if (domain && typeof domain === 'string') { | ||
if (domainListeners[domain]) { | ||
return domainListeners[domain]; | ||
} | ||
if (domain && typeof domain === 'string') { | ||
if (domainListeners[domain]) { | ||
return domainListeners[domain]; | ||
} | ||
if (domainListeners[__DOMAIN_REGEX__]) { | ||
for (const _ref of domainListeners[__DOMAIN_REGEX__]) { | ||
const { | ||
regex, | ||
listener | ||
} = _ref; | ||
if (domainListeners[__DOMAIN_REGEX__]) { | ||
for (var _i4 = 0, _domainListeners$__DO2 = domainListeners[__DOMAIN_REGEX__], _length4 = _domainListeners$__DO2 == null ? 0 : _domainListeners$__DO2.length; _i4 < _length4; _i4++) { | ||
var _ref5 = _domainListeners$__DO2[_i4]; | ||
var regex = _ref5.regex, | ||
listener = _ref5.listener; | ||
if (matchDomain(regex, domain)) { | ||
return listener; | ||
} | ||
} | ||
} | ||
if ((0, _src.matchDomain)(regex, domain)) { | ||
return listener; | ||
} | ||
} | ||
} | ||
} | ||
if (domainListeners[WILDCARD]) { | ||
return domainListeners[WILDCARD]; | ||
} | ||
if (domainListeners[_conf.WILDCARD]) { | ||
return domainListeners[_conf.WILDCARD]; | ||
} | ||
} | ||
} | ||
export function addRequestListener(_ref6, listener) { | ||
var name = _ref6.name, | ||
win = _ref6.win, | ||
domain = _ref6.domain; | ||
function addRequestListener({ | ||
name, | ||
win, | ||
domain | ||
}, listener) { | ||
const requestListeners = (0, _global.windowStore)('requestListeners'); | ||
if (!name || typeof name !== 'string') { | ||
throw new Error(`Name required to add request listener`); | ||
} | ||
if (!name || typeof name !== 'string') { | ||
throw new Error('Name required to add request listener'); | ||
if (Array.isArray(win)) { | ||
const listenersCollection = []; | ||
for (const item of win) { | ||
listenersCollection.push(addRequestListener({ | ||
name, | ||
domain, | ||
win: item | ||
}, listener)); | ||
} | ||
if (Array.isArray(win)) { | ||
var listenersCollection = []; | ||
for (var _i6 = 0, _win2 = win, _length6 = _win2 == null ? 0 : _win2.length; _i6 < _length6; _i6++) { | ||
var item = _win2[_i6]; | ||
listenersCollection.push(addRequestListener({ name: name, domain: domain, win: item }, listener)); | ||
return { | ||
cancel() { | ||
for (const cancelListener of listenersCollection) { | ||
cancelListener.cancel(); | ||
} | ||
} | ||
return { | ||
cancel: function cancel() { | ||
for (var _i8 = 0, _length8 = listenersCollection == null ? 0 : listenersCollection.length; _i8 < _length8; _i8++) { | ||
var cancelListener = listenersCollection[_i8]; | ||
cancelListener.cancel(); | ||
} | ||
} | ||
}; | ||
}; | ||
} | ||
if (Array.isArray(domain)) { | ||
const listenersCollection = []; | ||
for (const item of domain) { | ||
listenersCollection.push(addRequestListener({ | ||
name, | ||
win, | ||
domain: item | ||
}, listener)); | ||
} | ||
if (Array.isArray(domain)) { | ||
var _listenersCollection = []; | ||
for (var _i10 = 0, _domain2 = domain, _length10 = _domain2 == null ? 0 : _domain2.length; _i10 < _length10; _i10++) { | ||
var _item = _domain2[_i10]; | ||
_listenersCollection.push(addRequestListener({ name: name, win: win, domain: _item }, listener)); | ||
return { | ||
cancel() { | ||
for (const cancelListener of listenersCollection) { | ||
cancelListener.cancel(); | ||
} | ||
} | ||
return { | ||
cancel: function cancel() { | ||
for (var _i12 = 0, _length12 = _listenersCollection == null ? 0 : _listenersCollection.length; _i12 < _length12; _i12++) { | ||
var cancelListener = _listenersCollection[_i12]; | ||
cancelListener.cancel(); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
var existingListener = getRequestListener({ name: name, win: win, domain: domain }); | ||
const existingListener = getRequestListener({ | ||
name, | ||
win, | ||
domain | ||
}); | ||
if (!win || win === WILDCARD) { | ||
win = global.WINDOW_WILDCARD; | ||
} | ||
if (!win || win === _conf.WILDCARD) { | ||
win = (0, _global.getWildcard)(); | ||
} | ||
domain = domain || WILDCARD; | ||
domain = domain || _conf.WILDCARD; | ||
if (existingListener) { | ||
if (win && domain) { | ||
throw new Error('Request listener already exists for ' + name + ' on domain ' + domain.toString() + ' for ' + (win === global.WINDOW_WILDCARD ? 'wildcard' : 'specified') + ' window'); | ||
} else if (win) { | ||
throw new Error('Request listener already exists for ' + name + ' for ' + (win === global.WINDOW_WILDCARD ? 'wildcard' : 'specified') + ' window'); | ||
} else if (domain) { | ||
throw new Error('Request listener already exists for ' + name + ' on domain ' + domain.toString()); | ||
} else { | ||
throw new Error('Request listener already exists for ' + name); | ||
} | ||
if (existingListener) { | ||
if (win && domain) { | ||
throw new Error(`Request listener already exists for ${name} on domain ${domain.toString()} for ${win === (0, _global.getWildcard)() ? 'wildcard' : 'specified'} window`); | ||
} else if (win) { | ||
throw new Error(`Request listener already exists for ${name} for ${win === (0, _global.getWildcard)() ? 'wildcard' : 'specified'} window`); | ||
} else if (domain) { | ||
throw new Error(`Request listener already exists for ${name} on domain ${domain.toString()}`); | ||
} else { | ||
throw new Error(`Request listener already exists for ${name}`); | ||
} | ||
} | ||
var nameListeners = requestListeners.getOrSet(win, function () { | ||
return {}; | ||
}); | ||
// $FlowFixMe | ||
var domainListeners = getOrSet(nameListeners, name, function () { | ||
return {}; | ||
}); | ||
const nameListeners = requestListeners.getOrSet(win, () => ({})); // $FlowFixMe | ||
var strDomain = domain.toString(); | ||
const domainListeners = (0, _src2.getOrSet)(nameListeners, name, () => ({})); | ||
const strDomain = domain.toString(); | ||
let regexListeners; | ||
let regexListener; | ||
var regexListeners = void 0; | ||
var regexListener = void 0; | ||
if ((0, _src2.isRegex)(domain)) { | ||
regexListeners = (0, _src2.getOrSet)(domainListeners, __DOMAIN_REGEX__, () => []); | ||
regexListener = { | ||
regex: domain, | ||
listener | ||
}; | ||
regexListeners.push(regexListener); | ||
} else { | ||
domainListeners[strDomain] = listener; | ||
} | ||
if (isRegex(domain)) { | ||
regexListeners = getOrSet(domainListeners, __DOMAIN_REGEX__, function () { | ||
return []; | ||
}); | ||
regexListener = { regex: domain, listener: listener }; | ||
regexListeners.push(regexListener); | ||
} else { | ||
domainListeners[strDomain] = listener; | ||
} | ||
return { | ||
cancel() { | ||
delete domainListeners[strDomain]; | ||
return { | ||
cancel: function cancel() { | ||
delete domainListeners[strDomain]; | ||
if (regexListener) { | ||
regexListeners.splice(regexListeners.indexOf(regexListener, 1)); | ||
if (regexListener) { | ||
regexListeners.splice(regexListeners.indexOf(regexListener, 1)); | ||
if (!regexListeners.length) { | ||
delete domainListeners[__DOMAIN_REGEX__]; | ||
} | ||
} | ||
if (!regexListeners.length) { | ||
delete domainListeners[__DOMAIN_REGEX__]; | ||
} | ||
} | ||
if (!Object.keys(domainListeners).length) { | ||
// $FlowFixMe | ||
delete nameListeners[name]; | ||
} // $FlowFixMe | ||
if (!Object.keys(domainListeners).length) { | ||
// $FlowFixMe | ||
delete nameListeners[name]; | ||
} | ||
// $FlowFixMe | ||
if (win && !Object.keys(nameListeners).length) { | ||
requestListeners.del(win); | ||
} | ||
} | ||
}; | ||
if (win && !Object.keys(nameListeners).length) { | ||
requestListeners.del(win); | ||
} | ||
} | ||
}; | ||
} |
@@ -1,132 +0,180 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
"use strict"; | ||
import { isWindowClosed, getDomain, isSameTopWindow } from 'cross-domain-utils/src'; | ||
import { addEventListener, noop } from 'belter/src'; | ||
exports.__esModule = true; | ||
exports.receiveMessage = receiveMessage; | ||
exports.setupGlobalReceiveMessage = setupGlobalReceiveMessage; | ||
exports.messageListener = messageListener; | ||
exports.listenForMessages = listenForMessages; | ||
import { WINDOW_PROP } from '../../conf'; | ||
import { markWindowKnown, needsGlobalMessagingForBrowser } from '../../lib'; | ||
import { deserializeMessage } from '../../serialize'; | ||
import { global, globalStore } from '../../global'; | ||
var _src = require("cross-domain-utils/src"); | ||
import { RECEIVE_MESSAGE_TYPES } from './types'; | ||
var _src2 = require("belter/src"); | ||
var receivedMessages = globalStore('receivedMessages'); | ||
var _lib = require("../../lib"); | ||
function parseMessage(message, source, origin) { | ||
var _serialize = require("../../serialize"); | ||
var parsedMessage = void 0; | ||
var _global = require("../../global"); | ||
try { | ||
parsedMessage = deserializeMessage(source, origin, message); | ||
} catch (err) { | ||
return; | ||
} | ||
var _types = require("./types"); | ||
if (!parsedMessage) { | ||
return; | ||
} | ||
function parseMessage(message, source, origin, { | ||
on, | ||
send | ||
}) { | ||
let parsedMessage; | ||
if ((typeof parsedMessage === 'undefined' ? 'undefined' : _typeof(parsedMessage)) !== 'object' || parsedMessage === null) { | ||
return; | ||
} | ||
try { | ||
parsedMessage = (0, _serialize.deserializeMessage)(source, origin, message, { | ||
on, | ||
send | ||
}); | ||
} catch (err) { | ||
return; | ||
} | ||
parsedMessage = parsedMessage[WINDOW_PROP.POSTROBOT]; | ||
if (!parsedMessage) { | ||
return; | ||
} | ||
if (!parsedMessage || (typeof parsedMessage === 'undefined' ? 'undefined' : _typeof(parsedMessage)) !== 'object' || parsedMessage === null) { | ||
return; | ||
} | ||
if (typeof parsedMessage !== 'object' || parsedMessage === null) { | ||
return; | ||
} | ||
if (!parsedMessage.type || typeof parsedMessage.type !== 'string') { | ||
return; | ||
} | ||
parsedMessage = parsedMessage[__POST_ROBOT__.__GLOBAL_KEY__]; | ||
if (!RECEIVE_MESSAGE_TYPES[parsedMessage.type]) { | ||
return; | ||
} | ||
if (!parsedMessage || typeof parsedMessage !== 'object' || parsedMessage === null) { | ||
return; | ||
} | ||
return parsedMessage; | ||
if (!parsedMessage.type || typeof parsedMessage.type !== 'string') { | ||
return; | ||
} | ||
if (!_types.RECEIVE_MESSAGE_TYPES[parsedMessage.type]) { | ||
return; | ||
} | ||
return parsedMessage; | ||
} | ||
export function receiveMessage(event) { | ||
function receiveMessage(event, { | ||
on, | ||
send | ||
}) { | ||
const receivedMessages = (0, _global.globalStore)('receivedMessages'); | ||
if (!window || window.closed) { | ||
throw new Error('Message recieved in closed window'); | ||
} | ||
if (!window || window.closed) { | ||
throw new Error(`Message recieved in closed window`); | ||
} | ||
try { | ||
if (!event.source) { | ||
return; | ||
} | ||
} catch (err) { | ||
return; | ||
try { | ||
if (!event.source) { | ||
return; | ||
} | ||
} catch (err) { | ||
return; | ||
} | ||
var source = event.source, | ||
origin = event.origin, | ||
data = event.data; | ||
let { | ||
source, | ||
origin, | ||
data | ||
} = event; | ||
if (__TEST__) { | ||
// $FlowFixMe | ||
origin = (0, _src.getDomain)(source); | ||
} | ||
if (__TEST__) { | ||
// $FlowFixMe | ||
origin = getDomain(source); | ||
} | ||
const message = parseMessage(data, source, origin, { | ||
on, | ||
send | ||
}); | ||
var message = parseMessage(data, source, origin); | ||
if (!message) { | ||
return; | ||
} | ||
if (!message) { | ||
return; | ||
} | ||
(0, _lib.markWindowKnown)(source); | ||
markWindowKnown(source); | ||
if (receivedMessages.has(message.id)) { | ||
return; | ||
} | ||
if (receivedMessages.has(message.id)) { | ||
return; | ||
} | ||
receivedMessages.set(message.id, true); | ||
receivedMessages.set(message.id, true); | ||
if ((0, _src.isWindowClosed)(source) && !message.fireAndForget) { | ||
return; | ||
} | ||
if (isWindowClosed(source) && !message.fireAndForget) { | ||
return; | ||
} | ||
_types.RECEIVE_MESSAGE_TYPES[message.type](source, origin, message, { | ||
on, | ||
send | ||
}); | ||
} | ||
RECEIVE_MESSAGE_TYPES[message.type](source, origin, message); | ||
function setupGlobalReceiveMessage({ | ||
on, | ||
send | ||
}) { | ||
const global = (0, _global.getGlobal)(); | ||
global.receiveMessage = global.receiveMessage || (message => receiveMessage(message, { | ||
on, | ||
send | ||
})); | ||
} | ||
export function messageListener(event) { | ||
function messageListener(event, { | ||
on, | ||
send | ||
}) { | ||
try { | ||
(0, _src2.noop)(event.source); | ||
} catch (err) { | ||
return; | ||
} // $FlowFixMe | ||
try { | ||
noop(event.source); | ||
} catch (err) { | ||
return; | ||
} | ||
// $FlowFixMe | ||
var messageEvent = { | ||
source: event.source || event.sourceElement, | ||
origin: event.origin || event.originalEvent && event.originalEvent.origin, | ||
data: event.data | ||
}; | ||
const messageEvent = { | ||
source: event.source || event.sourceElement, | ||
origin: event.origin || event.originalEvent && event.originalEvent.origin, | ||
data: event.data | ||
}; | ||
if (!messageEvent.source) { | ||
return; | ||
} | ||
if (!messageEvent.source) { | ||
return; | ||
} | ||
if (!messageEvent.origin) { | ||
throw new Error('Post message did not have origin domain'); | ||
} | ||
if (!messageEvent.origin) { | ||
throw new Error(`Post message did not have origin domain`); | ||
} | ||
if (__TEST__) { | ||
if (needsGlobalMessagingForBrowser() && isSameTopWindow(messageEvent.source, window) === false) { | ||
return; | ||
} | ||
if (__TEST__) { | ||
if ((0, _lib.needsGlobalMessagingForBrowser)() && (0, _src.isSameTopWindow)(messageEvent.source, window) === false) { | ||
return; | ||
} | ||
} | ||
receiveMessage(messageEvent); | ||
receiveMessage(messageEvent, { | ||
on, | ||
send | ||
}); | ||
} | ||
export function listenForMessages() { | ||
function listenForMessages({ | ||
on, | ||
send | ||
}) { | ||
return (0, _global.globalStore)().getOrSet('postMessageListeners', () => { | ||
// $FlowFixMe | ||
addEventListener(window, 'message', messageListener); | ||
} | ||
global.receiveMessage = receiveMessage; | ||
return (0, _src2.addEventListener)(window, 'message', event => { | ||
// $FlowFixMe | ||
messageListener(event, { | ||
on, | ||
send | ||
}); | ||
}); | ||
}); | ||
} |
@@ -1,117 +0,160 @@ | ||
var _RECEIVE_MESSAGE_TYPE; | ||
"use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
exports.__esModule = true; | ||
exports.RECEIVE_MESSAGE_TYPES = void 0; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { isWindowClosed, matchDomain, stringifyDomainPattern } from 'cross-domain-utils/src'; | ||
import { noop } from 'belter/src'; | ||
var _src = require("zalgo-promise/src"); | ||
import { MESSAGE_TYPE, MESSAGE_ACK, MESSAGE_NAME } from '../../conf'; | ||
import { sendMessage } from '../send'; | ||
import { getRequestListener, getResponseListener, deleteResponseListener, isResponseListenerErrored } from '../listeners'; | ||
var _src2 = require("cross-domain-utils/src"); | ||
var _src3 = require("belter/src"); | ||
export var RECEIVE_MESSAGE_TYPES = (_RECEIVE_MESSAGE_TYPE = {}, _RECEIVE_MESSAGE_TYPE[MESSAGE_TYPE.REQUEST] = function (source, origin, message) { | ||
var _conf = require("../../conf"); | ||
var options = getRequestListener({ name: message.name, win: source, domain: origin }); | ||
var _send = require("../send"); | ||
var logName = message.name === MESSAGE_NAME.METHOD && message.data && typeof message.data.name === 'string' ? message.data.name + '()' : message.name; | ||
var _listeners = require("../listeners"); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
const RECEIVE_MESSAGE_TYPES = { | ||
[_conf.MESSAGE_TYPE.REQUEST](source, origin, message, { | ||
on, | ||
send | ||
}) { | ||
const options = (0, _listeners.getRequestListener)({ | ||
name: message.name, | ||
win: source, | ||
domain: origin | ||
}); | ||
const logName = message.name === _conf.MESSAGE_NAME.METHOD && message.data && typeof message.data.name === 'string' ? `${message.data.name}()` : message.name; | ||
if (__DEBUG__) { | ||
// eslint-disable-next-line no-console | ||
console.info('receive::req', logName, origin, '\n\n', message.data); | ||
// eslint-disable-next-line no-console | ||
console.info('receive::req', logName, origin, '\n\n', message.data); | ||
} | ||
function sendResponse(type, ack) { | ||
var response = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
function sendResponse(type, ack, response = {}) { | ||
if (message.fireAndForget || (0, _src2.isWindowClosed)(source)) { | ||
return; | ||
} | ||
if (message.fireAndForget || isWindowClosed(source)) { | ||
return ZalgoPromise.resolve(); | ||
if (__DEBUG__ && type !== _conf.MESSAGE_TYPE.ACK) { | ||
if (ack === _conf.MESSAGE_ACK.SUCCESS) { | ||
// $FlowFixMe | ||
console.info('respond::res', logName, origin, '\n\n', response.data); // eslint-disable-line no-console | ||
} else if (ack === _conf.MESSAGE_ACK.ERROR) { | ||
// $FlowFixMe | ||
console.error('respond::err', logName, origin, '\n\n', response.error); // eslint-disable-line no-console | ||
} | ||
} // $FlowFixMe | ||
if (__DEBUG__ && type !== MESSAGE_TYPE.ACK) { | ||
if (ack === MESSAGE_ACK.SUCCESS) { | ||
// $FlowFixMe | ||
console.info('respond::res', logName, origin, '\n\n', response.data); // eslint-disable-line no-console | ||
} else if (ack === MESSAGE_ACK.ERROR) { | ||
// $FlowFixMe | ||
console.error('respond::err', logName, origin, '\n\n', response.error); // eslint-disable-line no-console | ||
} | ||
} | ||
// $FlowFixMe | ||
return sendMessage(source, origin, _extends({ | ||
type: type, | ||
ack: ack, | ||
hash: message.hash, | ||
name: message.name | ||
}, response)); | ||
(0, _send.sendMessage)(source, origin, _extends({ | ||
type, | ||
ack, | ||
hash: message.hash, | ||
name: message.name | ||
}, response), { | ||
on, | ||
send | ||
}); | ||
} | ||
return ZalgoPromise.all([sendResponse(MESSAGE_TYPE.ACK), ZalgoPromise['try'](function () { | ||
return _src.ZalgoPromise.all([sendResponse(_conf.MESSAGE_TYPE.ACK), _src.ZalgoPromise.try(() => { | ||
if (!options) { | ||
throw new Error(`No handler found for post message: ${message.name} from ${origin} in ${window.location.protocol}//${window.location.host}${window.location.pathname}`); | ||
} | ||
if (!options) { | ||
throw new Error('No handler found for post message: ' + message.name + ' from ' + origin + ' in ' + window.location.protocol + '//' + window.location.host + window.location.pathname); | ||
} | ||
if (!(0, _src2.matchDomain)(options.domain, origin)) { | ||
throw new Error(`Request origin ${origin} does not match domain ${options.domain.toString()}`); | ||
} | ||
if (!matchDomain(options.domain, origin)) { | ||
throw new Error('Request origin ' + origin + ' does not match domain ' + options.domain.toString()); | ||
} | ||
var data = message.data; | ||
return options.handler({ source: source, origin: origin, data: data }); | ||
}).then(function (data) { | ||
return sendResponse(MESSAGE_TYPE.RESPONSE, MESSAGE_ACK.SUCCESS, { data: data }); | ||
}, function (error) { | ||
return sendResponse(MESSAGE_TYPE.RESPONSE, MESSAGE_ACK.ERROR, { error: error }); | ||
})]).then(noop)['catch'](function (err) { | ||
if (options && options.handleError) { | ||
return options.handleError(err); | ||
} else { | ||
throw err; | ||
} | ||
const data = message.data; | ||
return options.handler({ | ||
source, | ||
origin, | ||
data | ||
}); | ||
}).then(data => { | ||
return sendResponse(_conf.MESSAGE_TYPE.RESPONSE, _conf.MESSAGE_ACK.SUCCESS, { | ||
data | ||
}); | ||
}, error => { | ||
return sendResponse(_conf.MESSAGE_TYPE.RESPONSE, _conf.MESSAGE_ACK.ERROR, { | ||
error | ||
}); | ||
})]).then(_src3.noop).catch(err => { | ||
if (options && options.handleError) { | ||
return options.handleError(err); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
}, _RECEIVE_MESSAGE_TYPE[MESSAGE_TYPE.ACK] = function (source, origin, message) { | ||
}, | ||
if (isResponseListenerErrored(message.hash)) { | ||
return; | ||
[_conf.MESSAGE_TYPE.ACK](source, origin, message) { | ||
if ((0, _listeners.isResponseListenerErrored)(message.hash)) { | ||
return; | ||
} | ||
var options = getResponseListener(message.hash); | ||
const options = (0, _listeners.getResponseListener)(message.hash); | ||
if (!options) { | ||
throw new Error('No handler found for post message ack for message: ' + message.name + ' from ' + origin + ' in ' + window.location.protocol + '//' + window.location.host + window.location.pathname); | ||
throw new Error(`No handler found for post message ack for message: ${message.name} from ${origin} in ${window.location.protocol}//${window.location.host}${window.location.pathname}`); | ||
} | ||
if (!matchDomain(options.domain, origin)) { | ||
throw new Error('Ack origin ' + origin + ' does not match domain ' + options.domain.toString()); | ||
if (!(0, _src2.matchDomain)(options.domain, origin)) { | ||
throw new Error(`Ack origin ${origin} does not match domain ${options.domain.toString()}`); | ||
} | ||
if (source !== options.win) { | ||
throw new Error(`Ack source does not match registered window`); | ||
} | ||
options.ack = true; | ||
}, _RECEIVE_MESSAGE_TYPE[MESSAGE_TYPE.RESPONSE] = function (source, origin, message) { | ||
}, | ||
if (isResponseListenerErrored(message.hash)) { | ||
return; | ||
[_conf.MESSAGE_TYPE.RESPONSE](source, origin, message) { | ||
if ((0, _listeners.isResponseListenerErrored)(message.hash)) { | ||
return; | ||
} | ||
var options = getResponseListener(message.hash); | ||
const options = (0, _listeners.getResponseListener)(message.hash); | ||
if (!options) { | ||
throw new Error('No handler found for post message response for message: ' + message.name + ' from ' + origin + ' in ' + window.location.protocol + '//' + window.location.host + window.location.pathname); | ||
throw new Error(`No handler found for post message response for message: ${message.name} from ${origin} in ${window.location.protocol}//${window.location.host}${window.location.pathname}`); | ||
} | ||
if (!matchDomain(options.domain, origin)) { | ||
throw new Error('Response origin ' + origin + ' does not match domain ' + stringifyDomainPattern(options.domain)); | ||
if (!(0, _src2.matchDomain)(options.domain, origin)) { | ||
throw new Error(`Response origin ${origin} does not match domain ${(0, _src2.stringifyDomainPattern)(options.domain)}`); | ||
} | ||
deleteResponseListener(message.hash); | ||
if (source !== options.win) { | ||
throw new Error(`Response source does not match registered window`); | ||
} | ||
if (message.ack === MESSAGE_ACK.ERROR) { | ||
return options.respond(message.error, null); | ||
} else if (message.ack === MESSAGE_ACK.SUCCESS) { | ||
var data = message.data; | ||
return options.respond(null, { source: source, origin: origin, data: data }); | ||
(0, _listeners.deleteResponseListener)(message.hash); | ||
const logName = message.name === _conf.MESSAGE_NAME.METHOD && message.data && typeof message.data.name === 'string' ? `${message.data.name}()` : message.name; | ||
if (message.ack === _conf.MESSAGE_ACK.ERROR) { | ||
if (__DEBUG__) { | ||
console.error('receive::err', logName, origin, '\n\n', message.error); // eslint-disable-line no-console | ||
} | ||
options.promise.reject(message.error); | ||
} else if (message.ack === _conf.MESSAGE_ACK.SUCCESS) { | ||
if (__DEBUG__) { | ||
console.info('receive::res', logName, origin, '\n\n', message.data); // eslint-disable-line no-console | ||
} | ||
options.promise.resolve({ | ||
source, | ||
origin, | ||
data: message.data | ||
}); | ||
} | ||
}, _RECEIVE_MESSAGE_TYPE); | ||
} | ||
}; | ||
exports.RECEIVE_MESSAGE_TYPES = RECEIVE_MESSAGE_TYPES; |
@@ -1,53 +0,48 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
"use strict"; | ||
import { isWindowClosed } from 'cross-domain-utils/src'; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { uniqueID, stringifyError } from 'belter/src'; | ||
exports.__esModule = true; | ||
exports.sendMessage = sendMessage; | ||
import { CONFIG, WINDOW_PROP } from '../../conf'; | ||
import { serializeMessage } from '../../serialize'; | ||
var _src = require("cross-domain-utils/src"); | ||
var _src2 = require("belter/src"); | ||
import { SEND_MESSAGE_STRATEGIES } from './strategies'; | ||
var _serialize = require("../../serialize"); | ||
export function sendMessage(win, domain, message) { | ||
return ZalgoPromise['try'](function () { | ||
var _serializeMessage; | ||
var _strategies = require("./strategies"); | ||
if (isWindowClosed(win)) { | ||
throw new Error('Window is closed'); | ||
} | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var serializedMessage = serializeMessage(win, domain, (_serializeMessage = {}, _serializeMessage[WINDOW_PROP.POSTROBOT] = _extends({ | ||
id: uniqueID() | ||
}, message), _serializeMessage)); | ||
function sendMessage(win, domain, message, { | ||
on, | ||
send | ||
}) { | ||
if ((0, _src.isWindowClosed)(win)) { | ||
throw new Error('Window is closed'); | ||
} | ||
var messages = []; | ||
const serializedMessage = (0, _serialize.serializeMessage)(win, domain, { | ||
[__POST_ROBOT__.__GLOBAL_KEY__]: _extends({ | ||
id: (0, _src2.uniqueID)() | ||
}, message) | ||
}, { | ||
on, | ||
send | ||
}); | ||
let success = false; | ||
let error; | ||
return ZalgoPromise.map(Object.keys(SEND_MESSAGE_STRATEGIES), function (strategyName) { | ||
for (const strategyName of Object.keys(_strategies.SEND_MESSAGE_STRATEGIES)) { | ||
try { | ||
_strategies.SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain); | ||
return ZalgoPromise['try'](function () { | ||
success = true; | ||
} catch (err) { | ||
error = error || err; | ||
} | ||
} | ||
if (!CONFIG.ALLOWED_POST_MESSAGE_METHODS[strategyName]) { | ||
throw new Error('Strategy disallowed: ' + strategyName); | ||
} | ||
return SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain); | ||
}).then(function () { | ||
messages.push(strategyName + ': success'); | ||
return true; | ||
}, function (err) { | ||
messages.push(strategyName + ': ' + stringifyError(err) + '\n'); | ||
return false; | ||
}); | ||
}).then(function (results) { | ||
var success = results.some(Boolean); | ||
var status = message.type + ' ' + message.name + ' ' + (success ? 'success' : 'error') + ':\n - ' + messages.join('\n - ') + '\n'; | ||
if (!success) { | ||
throw new Error(status); | ||
} | ||
}); | ||
}); | ||
if (!success) { | ||
throw error; | ||
} | ||
} |
@@ -1,107 +0,106 @@ | ||
import { isSameDomain, isSameTopWindow, isActuallySameDomain, getActualDomain, getDomain } from 'cross-domain-utils/src'; | ||
"use strict"; | ||
import { SEND_STRATEGY, PROTOCOL, WILDCARD, WINDOW_PROP } from '../../conf'; | ||
import { needsGlobalMessagingForBrowser } from '../../lib'; | ||
exports.__esModule = true; | ||
exports.SEND_MESSAGE_STRATEGIES = void 0; | ||
export var SEND_MESSAGE_STRATEGIES = {}; | ||
var _src = require("cross-domain-utils/src"); | ||
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.POST_MESSAGE] = function (win, serializedMessage, domain) { | ||
var _conf = require("../../conf"); | ||
if (__TEST__) { | ||
if (needsGlobalMessagingForBrowser() && isSameTopWindow(window, win) === false) { | ||
return; | ||
} | ||
} | ||
var _lib = require("../../lib"); | ||
var domains = void 0; | ||
var _global = require("../../global"); | ||
if (Array.isArray(domain)) { | ||
domains = domain; | ||
} else if (typeof domain === 'string') { | ||
domains = [domain]; | ||
} else { | ||
domains = [WILDCARD]; | ||
var _bridge = require("../../bridge"); | ||
const SEND_MESSAGE_STRATEGIES = {}; | ||
exports.SEND_MESSAGE_STRATEGIES = SEND_MESSAGE_STRATEGIES; | ||
SEND_MESSAGE_STRATEGIES[_conf.SEND_STRATEGY.POST_MESSAGE] = (win, serializedMessage, domain) => { | ||
if (__TEST__) { | ||
if ((0, _lib.needsGlobalMessagingForBrowser)() && (0, _src.isSameTopWindow)(window, win) === false) { | ||
return; | ||
} | ||
} | ||
domains = domains.map(function (dom) { | ||
let domains; | ||
if (dom.indexOf(PROTOCOL.MOCK) === 0) { | ||
if (Array.isArray(domain)) { | ||
domains = domain; | ||
} else if (typeof domain === 'string') { | ||
domains = [domain]; | ||
} else { | ||
domains = [_conf.WILDCARD]; | ||
} | ||
if (window.location.protocol === PROTOCOL.FILE) { | ||
return WILDCARD; | ||
} | ||
domains = domains.map(dom => { | ||
if (dom.indexOf(_src.PROTOCOL.MOCK) === 0) { | ||
if (window.location.protocol === _src.PROTOCOL.FILE) { | ||
return _conf.WILDCARD; | ||
} | ||
if (!isActuallySameDomain(win)) { | ||
throw new Error('Attempting to send messsage to mock domain ' + dom + ', but window is actually cross-domain'); | ||
} | ||
if (!(0, _src.isActuallySameDomain)(win)) { | ||
throw new Error(`Attempting to send messsage to mock domain ${dom}, but window is actually cross-domain`); | ||
} // $FlowFixMe | ||
// $FlowFixMe | ||
return getActualDomain(win); | ||
} | ||
if (dom.indexOf(PROTOCOL.FILE) === 0) { | ||
return WILDCARD; | ||
} | ||
return (0, _src.getActualDomain)(win); | ||
} | ||
return dom; | ||
}); | ||
if (dom.indexOf(_src.PROTOCOL.FILE) === 0) { | ||
return _conf.WILDCARD; | ||
} | ||
domains.forEach(function (dom) { | ||
return win.postMessage(serializedMessage, dom); | ||
}); | ||
return dom; | ||
}); | ||
domains.forEach(dom => { | ||
win.postMessage(serializedMessage, dom); | ||
}); | ||
}; | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
var _require = require('../../bridge'), | ||
sendBridgeMessage = _require.sendBridgeMessage, | ||
needsBridgeForBrowser = _require.needsBridgeForBrowser, | ||
isBridge = _require.isBridge; | ||
SEND_MESSAGE_STRATEGIES[_conf.SEND_STRATEGY.BRIDGE] = (win, serializedMessage, domain) => { | ||
if (!(0, _bridge.needsBridgeForBrowser)() && !(0, _bridge.isBridge)()) { | ||
return; | ||
} | ||
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.BRIDGE] = function (win, serializedMessage, domain) { | ||
if ((0, _src.isSameDomain)(win)) { | ||
throw new Error(`Post message through bridge disabled between same domain windows`); | ||
} | ||
if (!needsBridgeForBrowser() && !isBridge()) { | ||
return; | ||
} | ||
if ((0, _src.isSameTopWindow)(window, win) !== false) { | ||
throw new Error(`Can only use bridge to communicate between two different windows, not between frames`); | ||
} | ||
if (isSameDomain(win)) { | ||
throw new Error('Post message through bridge disabled between same domain windows'); | ||
} | ||
if (isSameTopWindow(window, win) !== false) { | ||
throw new Error('Can only use bridge to communicate between two different windows, not between frames'); | ||
} | ||
return sendBridgeMessage(win, domain, serializedMessage); | ||
}; | ||
(0, _bridge.sendBridgeMessage)(win, domain, serializedMessage); | ||
}; | ||
} | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__ || __POST_ROBOT__.__GLOBAL_MESSAGE_SUPPORT__) { | ||
SEND_MESSAGE_STRATEGIES[_conf.SEND_STRATEGY.GLOBAL] = (win, serializedMessage) => { | ||
if (!(0, _lib.needsGlobalMessagingForBrowser)()) { | ||
return; | ||
} | ||
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.GLOBAL] = function (win, serializedMessage) { | ||
if (!(0, _src.isSameDomain)(win)) { | ||
throw new Error(`Post message through global disabled between different domain windows`); | ||
} | ||
if (!needsGlobalMessagingForBrowser()) { | ||
return; | ||
} | ||
if ((0, _src.isSameTopWindow)(window, win) !== false) { | ||
throw new Error(`Can only use global to communicate between two different windows, not between frames`); | ||
} // $FlowFixMe | ||
if (!isSameDomain(win)) { | ||
throw new Error('Post message through global disabled between different domain windows'); | ||
} | ||
if (isSameTopWindow(window, win) !== false) { | ||
throw new Error('Can only use global to communicate between two different windows, not between frames'); | ||
} | ||
const foreignGlobal = (0, _global.getGlobal)(win); | ||
// $FlowFixMe | ||
var foreignGlobal = win[WINDOW_PROP.POSTROBOT]; | ||
if (!foreignGlobal) { | ||
throw new Error(`Can not find postRobot global on foreign window`); | ||
} | ||
if (!foreignGlobal) { | ||
throw new Error('Can not find postRobot global on foreign window'); | ||
} | ||
return foreignGlobal.receiveMessage({ | ||
source: window, | ||
origin: getDomain(), | ||
data: serializedMessage | ||
}); | ||
}; | ||
foreignGlobal.receiveMessage({ | ||
source: window, | ||
origin: (0, _src.getDomain)(), | ||
data: serializedMessage | ||
}); | ||
}; | ||
} |
@@ -1,1 +0,3 @@ | ||
import { MESSAGE_TYPE, MESSAGE_ACK } from '../conf'; | ||
"use strict"; | ||
var _conf = require("../conf"); |
@@ -1,90 +0,102 @@ | ||
import 'cross-domain-utils/src'; | ||
import { WeakMap } from 'cross-domain-safe-weakmap/src'; | ||
import { getOrSet } from 'belter/src'; | ||
"use strict"; | ||
import { WINDOW_PROP } from './conf'; | ||
exports.__esModule = true; | ||
exports.getGlobal = getGlobal; | ||
exports.globalStore = globalStore; | ||
exports.getWildcard = getWildcard; | ||
exports.windowStore = windowStore; | ||
exports.WildCard = void 0; | ||
export var global = window[WINDOW_PROP.POSTROBOT] = window[WINDOW_PROP.POSTROBOT] || {}; | ||
var winStore = global.windowStore = global.windowStore || new WeakMap(); | ||
var _src = require("cross-domain-safe-weakmap/src"); | ||
var getObj = function getObj() { | ||
return {}; | ||
}; | ||
var _src2 = require("belter/src"); | ||
// $FlowFixMe | ||
export function windowStore(key) { | ||
var defStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getObj; | ||
function getGlobal(win = window) { | ||
if (win !== window) { | ||
return win[__POST_ROBOT__.__GLOBAL_KEY__]; | ||
} | ||
const global = win[__POST_ROBOT__.__GLOBAL_KEY__] = win[__POST_ROBOT__.__GLOBAL_KEY__] || {}; | ||
return global; | ||
} | ||
function getStore(win) { | ||
return winStore.getOrSet(win, defStore); | ||
} | ||
const getObj = () => ({}); | ||
// $FlowFixMe | ||
function globalStore(key = 'store', defStore = getObj) { | ||
return (0, _src2.getOrSet)(getGlobal(), key, () => { | ||
let store = defStore(); | ||
return { | ||
has: function has(win) { | ||
var store = getStore(win); | ||
return store.hasOwnProperty(key); | ||
}, | ||
get: function get(win, defVal) { | ||
var store = getStore(win); | ||
// $FlowFixMe | ||
return store.hasOwnProperty(key) ? store[key] : defVal; | ||
}, | ||
set: function set(win, val) { | ||
var store = getStore(win); | ||
store[key] = val; | ||
return val; | ||
}, | ||
del: function del(win) { | ||
var store = getStore(win); | ||
delete store[key]; | ||
}, | ||
getOrSet: function getOrSet(win, getter) { | ||
var store = getStore(win); | ||
if (store.hasOwnProperty(key)) { | ||
return store[key]; | ||
} | ||
var val = getter(); | ||
store[key] = val; | ||
return val; | ||
} | ||
has: storeKey => { | ||
return store.hasOwnProperty(storeKey); | ||
}, | ||
get: (storeKey, defVal) => { | ||
// $FlowFixMe | ||
return store.hasOwnProperty(storeKey) ? store[storeKey] : defVal; | ||
}, | ||
set: (storeKey, val) => { | ||
store[storeKey] = val; | ||
return val; | ||
}, | ||
del: storeKey => { | ||
delete store[storeKey]; | ||
}, | ||
getOrSet: (storeKey, getter) => { | ||
// $FlowFixMe | ||
return (0, _src2.getOrSet)(store, storeKey, getter); | ||
}, | ||
reset: () => { | ||
store = defStore(); | ||
}, | ||
keys: () => { | ||
return Object.keys(store); | ||
} | ||
}; | ||
}); | ||
} | ||
class WildCard {} | ||
exports.WildCard = WildCard; | ||
function getWildcard() { | ||
const global = getGlobal(); | ||
global.WINDOW_WILDCARD = global.WINDOW_WILDCARD || new WildCard(); | ||
return global.WINDOW_WILDCARD; | ||
} | ||
// $FlowFixMe | ||
export function globalStore(key) { | ||
var defStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getObj; | ||
function windowStore(key = 'store', defStore = getObj) { | ||
return globalStore('windowStore').getOrSet(key, () => { | ||
const winStore = new _src.WeakMap(); | ||
var store = getOrSet(global, key, defStore); | ||
const getStore = win => { | ||
return winStore.getOrSet(win, defStore); | ||
}; | ||
return { | ||
has: function has(storeKey) { | ||
return store.hasOwnProperty(storeKey); | ||
}, | ||
get: function get(storeKey, defVal) { | ||
// $FlowFixMe | ||
return store.hasOwnProperty(storeKey) ? store[storeKey] : defVal; | ||
}, | ||
set: function set(storeKey, val) { | ||
store[storeKey] = val; | ||
return val; | ||
}, | ||
del: function del(storeKey) { | ||
delete store[storeKey]; | ||
}, | ||
getOrSet: function getOrSet(storeKey, getter) { | ||
if (store.hasOwnProperty(storeKey)) { | ||
return store[storeKey]; | ||
} | ||
var val = getter(); | ||
store[storeKey] = val; | ||
return val; | ||
}, | ||
reset: function reset() { | ||
store = defStore(); | ||
}, | ||
keys: function keys() { | ||
return Object.keys(store); | ||
} | ||
has: win => { | ||
const store = getStore(win); | ||
return store.hasOwnProperty(key); | ||
}, | ||
get: (win, defVal) => { | ||
const store = getStore(win); // $FlowFixMe | ||
return store.hasOwnProperty(key) ? store[key] : defVal; | ||
}, | ||
set: (win, val) => { | ||
const store = getStore(win); | ||
store[key] = val; | ||
return val; | ||
}, | ||
del: win => { | ||
const store = getStore(win); | ||
delete store[key]; | ||
}, | ||
getOrSet: (win, getter) => { | ||
const store = getStore(win); | ||
return (0, _src2.getOrSet)(store, key, getter); | ||
} | ||
}; | ||
}); | ||
} |
@@ -0,7 +1,79 @@ | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _exportNames = { | ||
Promise: true, | ||
ProxyWindow: true, | ||
serializeMessage: true, | ||
deserializeMessage: true, | ||
toProxyWindow: true, | ||
on: true, | ||
once: true, | ||
send: true, | ||
markWindowKnown: true, | ||
cleanUpWindow: true, | ||
bridge: true, | ||
setup: true | ||
}; | ||
exports.bridge = exports.cleanUpWindow = exports.markWindowKnown = exports.send = exports.once = exports.on = exports.toProxyWindow = exports.deserializeMessage = exports.serializeMessage = exports.ProxyWindow = exports.Promise = void 0; | ||
// eslint-disable-next-line import/no-namespace | ||
import * as INTERFACE from './interface'; | ||
var _setup = require("./setup"); | ||
export * from './interface'; | ||
export default INTERFACE; | ||
exports.setup = _setup.setup; | ||
exports.serializeMessage = _setup.serializeMessage; | ||
exports.deserializeMessage = _setup.deserializeMessage; | ||
exports.toProxyWindow = _setup.toProxyWindow; | ||
var _bridge = require("./bridge"); | ||
var _src = require("zalgo-promise/src"); | ||
exports.Promise = _src.ZalgoPromise; | ||
var _types = require("./types"); | ||
Object.keys(_types).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
exports[key] = _types[key]; | ||
}); | ||
var _serialize = require("./serialize"); | ||
exports.ProxyWindow = _serialize.ProxyWindow; | ||
var _public = require("./public"); | ||
exports.on = _public.on; | ||
exports.once = _public.once; | ||
exports.send = _public.send; | ||
var _lib = require("./lib"); | ||
exports.markWindowKnown = _lib.markWindowKnown; | ||
var _clean = require("./clean"); | ||
exports.cleanUpWindow = _clean.cleanUpWindow; | ||
let bridge; | ||
exports.bridge = bridge; | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
exports.bridge = bridge = { | ||
setupBridge: _bridge.setupBridge, | ||
openBridge: _bridge.openBridge, | ||
linkWindow: _bridge.linkWindow, | ||
linkUrl: _bridge.linkUrl, | ||
isBridge: _bridge.isBridge, | ||
needsBridge: _bridge.needsBridge, | ||
needsBridgeForBrowser: _bridge.needsBridgeForBrowser, | ||
hasBridge: _bridge.hasBridge, | ||
needsBridgeForWin: _bridge.needsBridgeForWin, | ||
needsBridgeForDomain: _bridge.needsBridgeForDomain, | ||
destroyBridges: _bridge.destroyBridges | ||
}; | ||
} | ||
if (__POST_ROBOT__.__AUTO_SETUP__) { | ||
(0, _setup.setup)(); | ||
} |
@@ -1,10 +0,14 @@ | ||
import { getUserAgent } from 'cross-domain-utils/src'; | ||
"use strict"; | ||
export function needsGlobalMessagingForBrowser() { | ||
exports.__esModule = true; | ||
exports.needsGlobalMessagingForBrowser = needsGlobalMessagingForBrowser; | ||
if (getUserAgent(window).match(/MSIE|rv:11|trident|edge\/12|edge\/13/i)) { | ||
return true; | ||
} | ||
var _src = require("cross-domain-utils/src"); | ||
return false; | ||
function needsGlobalMessagingForBrowser() { | ||
if ((0, _src.getUserAgent)(window).match(/MSIE|rv:11|trident|edge\/12|edge\/13/i)) { | ||
return true; | ||
} | ||
return false; | ||
} |
@@ -1,64 +0,113 @@ | ||
import { getAncestor } from 'cross-domain-utils/src'; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { noop, uniqueID, once, weakMapMemoizePromise } from 'belter/src'; | ||
"use strict"; | ||
import { MESSAGE_NAME, WILDCARD } from '../conf'; | ||
import { global, windowStore } from '../global'; | ||
exports.__esModule = true; | ||
exports.sayHello = sayHello; | ||
exports.getWindowInstanceID = getWindowInstanceID; | ||
exports.initHello = initHello; | ||
exports.awaitWindowHello = awaitWindowHello; | ||
global.instanceID = global.instanceID || uniqueID(); | ||
var helloPromises = windowStore('helloPromises'); | ||
var _src = require("cross-domain-utils/src"); | ||
var _src2 = require("zalgo-promise/src"); | ||
var _src3 = require("belter/src"); | ||
var _conf = require("../conf"); | ||
var _global = require("../global"); | ||
function getInstanceID() { | ||
return (0, _global.globalStore)('instance').getOrSet('instanceID', _src3.uniqueID); | ||
} | ||
function getHelloPromise(win) { | ||
return helloPromises.getOrSet(win, function () { | ||
return new ZalgoPromise(); | ||
}); | ||
const helloPromises = (0, _global.windowStore)('helloPromises'); | ||
return helloPromises.getOrSet(win, () => new _src2.ZalgoPromise()); | ||
} | ||
var listenForHello = once(function () { | ||
global.on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, function (_ref) { | ||
var source = _ref.source, | ||
origin = _ref.origin; | ||
getHelloPromise(source).resolve({ win: source, domain: origin }); | ||
return { instanceID: global.instanceID }; | ||
function listenForHello({ | ||
on | ||
}) { | ||
return on(_conf.MESSAGE_NAME.HELLO, { | ||
domain: _conf.WILDCARD | ||
}, ({ | ||
source, | ||
origin | ||
}) => { | ||
getHelloPromise(source).resolve({ | ||
win: source, | ||
domain: origin | ||
}); | ||
}); | ||
return { | ||
instanceID: getInstanceID() | ||
}; | ||
}); | ||
} | ||
export function sayHello(win) { | ||
return global.send(win, MESSAGE_NAME.HELLO, { instanceID: global.instanceID }, { domain: WILDCARD, timeout: -1 }).then(function (_ref2) { | ||
var origin = _ref2.origin, | ||
instanceID = _ref2.data.instanceID; | ||
getHelloPromise(win).resolve({ win: win, domain: origin }); | ||
return { win: win, domain: origin, instanceID: instanceID }; | ||
function sayHello(win, { | ||
send | ||
}) { | ||
return send(win, _conf.MESSAGE_NAME.HELLO, { | ||
instanceID: getInstanceID() | ||
}, { | ||
domain: _conf.WILDCARD, | ||
timeout: -1 | ||
}).then(({ | ||
origin, | ||
data: { | ||
instanceID | ||
} | ||
}) => { | ||
getHelloPromise(win).resolve({ | ||
win, | ||
domain: origin | ||
}); | ||
return { | ||
win, | ||
domain: origin, | ||
instanceID | ||
}; | ||
}); | ||
} | ||
export var getWindowInstanceID = weakMapMemoizePromise(function (win) { | ||
return sayHello(win).then(function (_ref3) { | ||
var instanceID = _ref3.instanceID; | ||
return instanceID; | ||
function getWindowInstanceID(win, { | ||
send | ||
}) { | ||
return (0, _global.windowStore)('windowInstanceIDPromises').getOrSet(win, () => { | ||
return sayHello(win, { | ||
send | ||
}).then(({ | ||
instanceID | ||
}) => instanceID); | ||
}); | ||
} | ||
function initHello({ | ||
on, | ||
send | ||
}) { | ||
return (0, _global.globalStore)('builtinListeners').getOrSet('helloListener', () => { | ||
const listener = listenForHello({ | ||
on | ||
}); | ||
}); | ||
const parent = (0, _src.getAncestor)(); | ||
export function initHello() { | ||
listenForHello(); | ||
var parent = getAncestor(); | ||
if (parent) { | ||
sayHello(parent)['catch'](noop); | ||
sayHello(parent, { | ||
send | ||
}).catch(_src3.noop); | ||
} | ||
return listener; | ||
}); | ||
} | ||
export function awaitWindowHello(win) { | ||
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5000; | ||
var name = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Window'; | ||
function awaitWindowHello(win, timeout = 5000, name = 'Window') { | ||
let promise = getHelloPromise(win); | ||
var promise = getHelloPromise(win); | ||
if (timeout !== -1) { | ||
promise = promise.timeout(timeout, new Error(`${name} did not load after ${timeout}ms`)); | ||
} | ||
if (timeout !== -1) { | ||
promise = promise.timeout(timeout, new Error(name + ' did not load after ' + timeout + 'ms')); | ||
} | ||
return promise; | ||
return promise; | ||
} |
@@ -1,3 +0,24 @@ | ||
export * from './hello'; | ||
export * from './compat'; | ||
export * from './windows'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _hello = require("./hello"); | ||
Object.keys(_hello).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _hello[key]; | ||
}); | ||
var _compat = require("./compat"); | ||
Object.keys(_compat).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _compat[key]; | ||
}); | ||
var _windows = require("./windows"); | ||
Object.keys(_windows).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _windows[key]; | ||
}); |
@@ -1,13 +0,17 @@ | ||
import 'cross-domain-utils/src'; | ||
"use strict"; | ||
import { windowStore } from '../global'; | ||
exports.__esModule = true; | ||
exports.markWindowKnown = markWindowKnown; | ||
exports.isWindowKnown = isWindowKnown; | ||
var knownWindows = windowStore('knownWindows'); | ||
var _global = require("../global"); | ||
export function markWindowKnown(win) { | ||
knownWindows.set(win, true); | ||
function markWindowKnown(win) { | ||
const knownWindows = (0, _global.windowStore)('knownWindows'); | ||
knownWindows.set(win, true); | ||
} | ||
export function isWindowKnown(win) { | ||
return knownWindows.get(win, false); | ||
function isWindowKnown(win) { | ||
const knownWindows = (0, _global.windowStore)('knownWindows'); | ||
return knownWindows.get(win, false); | ||
} |
@@ -1,7 +0,17 @@ | ||
import { getAncestor } from 'cross-domain-utils/src'; | ||
"use strict"; | ||
export * from './client'; | ||
export * from './server'; | ||
export * from './config'; | ||
exports.__esModule = true; | ||
export var parent = getAncestor(); | ||
var _on = require("./on"); | ||
Object.keys(_on).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _on[key]; | ||
}); | ||
var _send = require("./send"); | ||
Object.keys(_send).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _send[key]; | ||
}); |
@@ -1,169 +0,204 @@ | ||
import { matchDomain, getDomain } from 'cross-domain-utils/src'; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { once, uniqueID, isRegex } from 'belter/src'; | ||
import { serializeType } from 'universal-serialize/src'; | ||
"use strict"; | ||
import { MESSAGE_NAME, WILDCARD, SERIALIZATION_TYPE } from '../conf'; | ||
import { global, windowStore, globalStore } from '../global'; | ||
exports.__esModule = true; | ||
exports.serializeFunction = serializeFunction; | ||
exports.deserializeFunction = deserializeFunction; | ||
import { ProxyWindow } from './window'; | ||
var _src = require("cross-domain-utils/src"); | ||
var methodStore = windowStore('methodStore'); | ||
var proxyWindowMethods = globalStore('proxyWindowMethods'); | ||
global.listeningForFunctions = global.listeningForFunctions || false; | ||
var _src2 = require("zalgo-promise/src"); | ||
function addMethod(id, val, name, source, domain) { | ||
if (ProxyWindow.isProxyWindow(source)) { | ||
proxyWindowMethods.set(id, { val: val, name: name, domain: domain, source: source }); | ||
} else { | ||
proxyWindowMethods.del(id); | ||
// $FlowFixMe | ||
var methods = methodStore.getOrSet(source, function () { | ||
return {}; | ||
}); | ||
methods[id] = { domain: domain, name: name, val: val, source: source }; | ||
} | ||
} | ||
var _src3 = require("belter/src"); | ||
function lookupMethod(source, id) { | ||
var methods = methodStore.getOrSet(source, function () { | ||
return {}; | ||
}); | ||
return methods[id] || proxyWindowMethods.get(id); | ||
} | ||
var _src4 = require("universal-serialize/src"); | ||
var listenForFunctionCalls = once(function () { | ||
if (global.listeningForFunctions) { | ||
return; | ||
} | ||
var _conf = require("../conf"); | ||
global.listeningForFunctions = true; | ||
var _global = require("../global"); | ||
global.on(MESSAGE_NAME.METHOD, { origin: WILDCARD }, function (_ref) { | ||
var source = _ref.source, | ||
origin = _ref.origin, | ||
data = _ref.data; | ||
var id = data.id, | ||
name = data.name; | ||
var _window = require("./window"); | ||
function addMethod(id, val, name, source, domain) { | ||
const methodStore = (0, _global.windowStore)('methodStore'); | ||
const proxyWindowMethods = (0, _global.globalStore)('proxyWindowMethods'); | ||
return ZalgoPromise['try'](function () { | ||
var meth = lookupMethod(source, id); | ||
if (_window.ProxyWindow.isProxyWindow(source)) { | ||
proxyWindowMethods.set(id, { | ||
val, | ||
name, | ||
domain, | ||
source | ||
}); | ||
} else { | ||
proxyWindowMethods.del(id); // $FlowFixMe | ||
if (!meth) { | ||
throw new Error('Could not find method \'' + data.name + '\' with id: ' + data.id + ' in ' + getDomain(window)); | ||
} | ||
const methods = methodStore.getOrSet(source, () => ({})); | ||
methods[id] = { | ||
domain, | ||
name, | ||
val, | ||
source | ||
}; | ||
} | ||
} | ||
var methodSource = meth.source, | ||
domain = meth.domain, | ||
val = meth.val; | ||
function lookupMethod(source, id) { | ||
const methodStore = (0, _global.windowStore)('methodStore'); | ||
const proxyWindowMethods = (0, _global.globalStore)('proxyWindowMethods'); | ||
const methods = methodStore.getOrSet(source, () => ({})); | ||
return methods[id] || proxyWindowMethods.get(id); | ||
} | ||
function listenForFunctionCalls({ | ||
on | ||
}) { | ||
return (0, _global.globalStore)('builtinListeners').getOrSet('functionCalls', () => { | ||
return on(_conf.MESSAGE_NAME.METHOD, { | ||
domain: _conf.WILDCARD | ||
}, ({ | ||
source, | ||
origin, | ||
data | ||
}) => { | ||
const { | ||
id, | ||
name | ||
} = data; | ||
const meth = lookupMethod(source, id); | ||
return ZalgoPromise['try'](function () { | ||
if (!matchDomain(domain, origin)) { | ||
// $FlowFixMe | ||
throw new Error('Method \'' + data.name + '\' domain ' + JSON.stringify(isRegex(meth.domain) ? meth.domain.source : meth.domain) + ' does not match origin ' + origin + ' in ' + getDomain(window)); | ||
} | ||
if (!meth) { | ||
throw new Error(`Could not find method '${data.name}' with id: ${data.id} in ${(0, _src.getDomain)(window)}`); | ||
} | ||
if (ProxyWindow.isProxyWindow(methodSource)) { | ||
// $FlowFixMe | ||
return methodSource.matchWindow(source).then(function (match) { | ||
// eslint-disable-line max-nested-callbacks | ||
if (!match) { | ||
throw new Error('Method call \'' + data.name + '\' failed - proxy window does not match source in ' + getDomain(window)); | ||
} | ||
}); | ||
} | ||
}).then(function () { | ||
return val.apply({ source: source, origin: origin }, data.args); | ||
}, function (err) { | ||
return ZalgoPromise['try'](function () { | ||
// eslint-disable-line max-nested-callbacks | ||
if (val.onError) { | ||
return val.onError(err); | ||
} | ||
}).then(function () { | ||
// eslint-disable-line max-nested-callbacks | ||
throw err; | ||
}); | ||
}).then(function (result) { | ||
return { result: result, id: id, name: name }; | ||
}); | ||
const { | ||
source: methodSource, | ||
domain, | ||
val | ||
} = meth; | ||
return _src2.ZalgoPromise.try(() => { | ||
if (!(0, _src.matchDomain)(domain, origin)) { | ||
// $FlowFixMe | ||
throw new Error(`Method '${data.name}' domain ${JSON.stringify((0, _src3.isRegex)(meth.domain) ? meth.domain.source : meth.domain)} does not match origin ${origin} in ${(0, _src.getDomain)(window)}`); | ||
} | ||
if (_window.ProxyWindow.isProxyWindow(methodSource)) { | ||
// $FlowFixMe | ||
return methodSource.matchWindow(source).then(match => { | ||
if (!match) { | ||
throw new Error(`Method call '${data.name}' failed - proxy window does not match source in ${(0, _src.getDomain)(window)}`); | ||
} | ||
}); | ||
} | ||
}).then(() => { | ||
return val.apply({ | ||
source, | ||
origin | ||
}, data.args); | ||
}, err => { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (val.onError) { | ||
return val.onError(err); | ||
} | ||
}).then(() => { | ||
throw err; | ||
}); | ||
}).then(result => { | ||
return { | ||
result, | ||
id, | ||
name | ||
}; | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
export function serializeFunction(destination, domain, val, key) { | ||
listenForFunctionCalls(); | ||
function serializeFunction(destination, domain, val, key, { | ||
on | ||
}) { | ||
listenForFunctionCalls({ | ||
on | ||
}); | ||
const id = val.__id__ || (0, _src3.uniqueID)(); | ||
destination = _window.ProxyWindow.unwrap(destination); | ||
const name = val.__name__ || val.name || key; | ||
var id = val.__id__ || uniqueID(); | ||
destination = ProxyWindow.unwrap(destination); | ||
var name = val.__name__ || val.name || key; | ||
if (_window.ProxyWindow.isProxyWindow(destination)) { | ||
addMethod(id, val, name, destination, domain); // $FlowFixMe | ||
if (ProxyWindow.isProxyWindow(destination)) { | ||
addMethod(id, val, name, destination, domain); | ||
destination.awaitWindow().then(win => { | ||
addMethod(id, val, name, win, domain); | ||
}); | ||
} else { | ||
addMethod(id, val, name, destination, domain); | ||
} | ||
// $FlowFixMe | ||
destination.awaitWindow().then(function (win) { | ||
addMethod(id, val, name, win, domain); | ||
}); | ||
} else { | ||
addMethod(id, val, name, destination, domain); | ||
} | ||
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION, { id: id, name: name }); | ||
return (0, _src4.serializeType)(_conf.SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION, { | ||
id, | ||
name | ||
}); | ||
} | ||
export function deserializeFunction(source, origin, _ref2) { | ||
var id = _ref2.id, | ||
name = _ref2.name; | ||
function deserializeFunction(source, origin, { | ||
id, | ||
name | ||
}, { | ||
send | ||
}) { | ||
const getDeserializedFunction = (opts = {}) => { | ||
function crossDomainFunctionWrapper() { | ||
let originalStack; | ||
var getDeserializedFunction = function getDeserializedFunction() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (__DEBUG__) { | ||
originalStack = new Error(`Original call to ${name}():`).stack; | ||
} | ||
function crossDomainFunctionWrapper() { | ||
var _arguments = arguments; | ||
return _window.ProxyWindow.toProxyWindow(source, { | ||
send | ||
}).awaitWindow().then(win => { | ||
const meth = lookupMethod(win, id); | ||
var originalStack = void 0; | ||
if (__DEBUG__) { | ||
originalStack = new Error('Original call to ' + name + '():').stack; | ||
if (meth && meth.val !== crossDomainFunctionWrapper) { | ||
return meth.val.apply({ | ||
source: window, | ||
origin: (0, _src.getDomain)() | ||
}, arguments); | ||
} else { | ||
return send(win, _conf.MESSAGE_NAME.METHOD, { | ||
id, | ||
name, | ||
args: Array.prototype.slice.call(arguments) | ||
}, { | ||
domain: origin, | ||
fireAndForget: opts.fireAndForget | ||
}).then(res => { | ||
if (!opts.fireAndForget) { | ||
return res.data.result; | ||
} | ||
return ProxyWindow.toProxyWindow(source).awaitWindow().then(function (win) { | ||
var meth = lookupMethod(win, id); | ||
if (meth && meth.val !== crossDomainFunctionWrapper) { | ||
return meth.val.apply({ source: window, origin: getDomain() }, _arguments); | ||
} else { | ||
return global.send(win, MESSAGE_NAME.METHOD, { id: id, name: name, args: Array.prototype.slice.call(_arguments) }, { domain: origin, fireAndForget: opts.fireAndForget }).then(function (res) { | ||
if (!opts.fireAndForget) { | ||
return res.data.result; | ||
} | ||
}); | ||
} | ||
})['catch'](function (err) { | ||
// $FlowFixMe | ||
if (__DEBUG__ && originalStack && err.stack) { | ||
// $FlowFixMe | ||
err.stack = err.stack + '\n\n' + originalStack; | ||
} | ||
throw err; | ||
}); | ||
}); | ||
} | ||
}).catch(err => { | ||
// $FlowFixMe | ||
if (__DEBUG__ && originalStack && err.stack) { | ||
// $FlowFixMe | ||
err.stack = `${err.stack}\n\n${originalStack}`; | ||
} | ||
crossDomainFunctionWrapper.__name__ = name; | ||
crossDomainFunctionWrapper.__origin__ = origin; | ||
crossDomainFunctionWrapper.__source__ = source; | ||
crossDomainFunctionWrapper.__id__ = id; | ||
throw err; | ||
}); | ||
} | ||
crossDomainFunctionWrapper.origin = origin; | ||
crossDomainFunctionWrapper.__name__ = name; | ||
crossDomainFunctionWrapper.__origin__ = origin; | ||
crossDomainFunctionWrapper.__source__ = source; | ||
crossDomainFunctionWrapper.__id__ = id; | ||
crossDomainFunctionWrapper.origin = origin; | ||
return crossDomainFunctionWrapper; | ||
}; | ||
return crossDomainFunctionWrapper; | ||
}; | ||
var crossDomainFunctionWrapper = getDeserializedFunction(); | ||
crossDomainFunctionWrapper.fireAndForget = getDeserializedFunction({ fireAndForget: true }); | ||
return crossDomainFunctionWrapper; | ||
const crossDomainFunctionWrapper = getDeserializedFunction(); | ||
crossDomainFunctionWrapper.fireAndForget = getDeserializedFunction({ | ||
fireAndForget: true | ||
}); | ||
return crossDomainFunctionWrapper; | ||
} |
@@ -1,4 +0,31 @@ | ||
export * from './serialize'; | ||
export * from './function'; | ||
export * from './promise'; | ||
export * from './window'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
var _serialize = require("./serialize"); | ||
Object.keys(_serialize).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _serialize[key]; | ||
}); | ||
var _function = require("./function"); | ||
Object.keys(_function).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _function[key]; | ||
}); | ||
var _promise = require("./promise"); | ||
Object.keys(_promise).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _promise[key]; | ||
}); | ||
var _window = require("./window"); | ||
Object.keys(_window).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _window[key]; | ||
}); |
@@ -1,22 +0,33 @@ | ||
import 'cross-domain-utils/src'; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { serializeType } from 'universal-serialize/src'; | ||
"use strict"; | ||
import { SERIALIZATION_TYPE } from '../conf'; | ||
exports.__esModule = true; | ||
exports.serializePromise = serializePromise; | ||
exports.deserializePromise = deserializePromise; | ||
import { serializeFunction } from './function'; | ||
import { ProxyWindow } from './window'; | ||
var _src = require("zalgo-promise/src"); | ||
export function serializePromise(destination, domain, val, key) { | ||
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, { | ||
then: serializeFunction(destination, domain, function (resolve, reject) { | ||
return val.then(resolve, reject); | ||
}, key) | ||
}); | ||
var _src2 = require("universal-serialize/src"); | ||
var _conf = require("../conf"); | ||
var _function = require("./function"); | ||
var _window = require("./window"); | ||
function serializePromise(destination, domain, val, key, { | ||
on, | ||
send | ||
}) { | ||
return (0, _src2.serializeType)(_conf.SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, { | ||
then: (0, _function.serializeFunction)(destination, domain, (resolve, reject) => val.then(resolve, reject), key, { | ||
on, | ||
send | ||
}) | ||
}); | ||
} | ||
export function deserializePromise(source, origin, _ref) { | ||
var then = _ref.then; | ||
return new ZalgoPromise(then); | ||
function deserializePromise(source, origin, { | ||
then | ||
}) { | ||
return new _src.ZalgoPromise(then); | ||
} |
@@ -1,32 +0,56 @@ | ||
import { isWindow } from 'cross-domain-utils/src'; | ||
import { TYPE, serialize, deserialize } from 'universal-serialize/src'; | ||
"use strict"; | ||
import { SERIALIZATION_TYPE } from '../conf'; | ||
exports.__esModule = true; | ||
exports.serializeMessage = serializeMessage; | ||
exports.deserializeMessage = deserializeMessage; | ||
import { serializeFunction, deserializeFunction } from './function'; | ||
import { serializePromise, deserializePromise } from './promise'; | ||
import { serializeWindow, deserializeWindow, ProxyWindow } from './window'; | ||
var _src = require("cross-domain-utils/src"); | ||
export function serializeMessage(destination, domain, obj) { | ||
var _serialize; | ||
var _src2 = require("universal-serialize/src"); | ||
return serialize(obj, (_serialize = {}, _serialize[TYPE.PROMISE] = function (val, key) { | ||
return serializePromise(destination, domain, val, key); | ||
}, _serialize[TYPE.FUNCTION] = function (val, key) { | ||
return serializeFunction(destination, domain, val, key); | ||
}, _serialize[TYPE.OBJECT] = function (val) { | ||
return isWindow(val) || ProxyWindow.isProxyWindow(val) ? serializeWindow(destination, domain, val) : val; | ||
}, _serialize)); | ||
var _conf = require("../conf"); | ||
var _function = require("./function"); | ||
var _promise = require("./promise"); | ||
var _window = require("./window"); | ||
function serializeMessage(destination, domain, obj, { | ||
on, | ||
send | ||
}) { | ||
return (0, _src2.serialize)(obj, { | ||
[_src2.TYPE.PROMISE]: (val, key) => (0, _promise.serializePromise)(destination, domain, val, key, { | ||
on, | ||
send | ||
}), | ||
[_src2.TYPE.FUNCTION]: (val, key) => (0, _function.serializeFunction)(destination, domain, val, key, { | ||
on, | ||
send | ||
}), | ||
[_src2.TYPE.OBJECT]: val => { | ||
return (0, _src.isWindow)(val) || _window.ProxyWindow.isProxyWindow(val) ? (0, _window.serializeWindow)(destination, domain, val, { | ||
on, | ||
send | ||
}) : val; | ||
} | ||
}); | ||
} | ||
export function deserializeMessage(source, origin, message) { | ||
var _deserialize; | ||
return deserialize(message, (_deserialize = {}, _deserialize[SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE] = function (serializedPromise) { | ||
return deserializePromise(source, origin, serializedPromise); | ||
}, _deserialize[SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION] = function (serializedFunction) { | ||
return deserializeFunction(source, origin, serializedFunction); | ||
}, _deserialize[SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW] = function (serializedWindow) { | ||
return deserializeWindow(source, origin, serializedWindow); | ||
}, _deserialize)); | ||
function deserializeMessage(source, origin, message, { | ||
on, | ||
send | ||
}) { | ||
return (0, _src2.deserialize)(message, { | ||
[_conf.SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE]: serializedPromise => (0, _promise.deserializePromise)(source, origin, serializedPromise), | ||
[_conf.SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION]: serializedFunction => (0, _function.deserializeFunction)(source, origin, serializedFunction, { | ||
on, | ||
send | ||
}), | ||
[_conf.SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW]: serializedWindow => (0, _window.deserializeWindow)(source, origin, serializedWindow, { | ||
on, | ||
send | ||
}) | ||
}); | ||
} |
@@ -1,297 +0,307 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
"use strict"; | ||
import { isSameDomain, isWindowClosed, getOpener, WINDOW_TYPE, isWindow } from 'cross-domain-utils/src'; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { uniqueID, memoizePromise } from 'belter/src'; | ||
import { serializeType } from 'universal-serialize/src'; | ||
exports.__esModule = true; | ||
exports.serializeWindow = serializeWindow; | ||
exports.deserializeWindow = deserializeWindow; | ||
exports.ProxyWindow = void 0; | ||
import { SERIALIZATION_TYPE } from '../conf'; | ||
import { windowStore, globalStore } from '../global'; | ||
import { getWindowInstanceID } from '../lib'; | ||
var _src = require("cross-domain-utils/src"); | ||
var winToProxyWindow = windowStore('winToProxyWindow'); | ||
var idToProxyWindow = globalStore('idToProxyWindow'); | ||
var _src2 = require("zalgo-promise/src"); | ||
var _src3 = require("belter/src"); | ||
var _src4 = require("universal-serialize/src"); | ||
var _conf = require("../conf"); | ||
var _global = require("../global"); | ||
var _lib = require("../lib"); | ||
var _bridge = require("../bridge"); | ||
function cleanupProxyWindows() { | ||
for (var _i2 = 0, _idToProxyWindow$keys2 = idToProxyWindow.keys(), _length2 = _idToProxyWindow$keys2 == null ? 0 : _idToProxyWindow$keys2.length; _i2 < _length2; _i2++) { | ||
var _id = _idToProxyWindow$keys2[_i2]; | ||
// $FlowFixMe | ||
if (idToProxyWindow.get(_id).shouldClean()) { | ||
idToProxyWindow.del(_id); | ||
} | ||
const idToProxyWindow = (0, _global.globalStore)('idToProxyWindow'); | ||
for (const id of idToProxyWindow.keys()) { | ||
// $FlowFixMe | ||
if (idToProxyWindow.get(id).shouldClean()) { | ||
idToProxyWindow.del(id); | ||
} | ||
} | ||
} | ||
export var ProxyWindow = function () { | ||
function ProxyWindow(serializedWindow, actualWindow) { | ||
_classCallCheck(this, ProxyWindow); | ||
class ProxyWindow { | ||
constructor(serializedWindow, actualWindow, { | ||
send | ||
}) { | ||
this.isProxyWindow = true; | ||
this.serializedWindow = void 0; | ||
this.actualWindow = void 0; | ||
this.actualWindowPromise = void 0; | ||
this.send = void 0; | ||
this.serializedWindow = serializedWindow; | ||
this.actualWindowPromise = new _src2.ZalgoPromise(); | ||
this.isProxyWindow = true; | ||
this.serializedWindow = serializedWindow; | ||
this.actualWindowPromise = new ZalgoPromise(); | ||
if (actualWindow) { | ||
this.setWindow(actualWindow); | ||
} | ||
this.serializedWindow.getInstanceID = memoizePromise(this.serializedWindow.getInstanceID); | ||
if (actualWindow) { | ||
this.setWindow(actualWindow); | ||
} | ||
ProxyWindow.prototype.getType = function getType() { | ||
return this.serializedWindow.type; | ||
}; | ||
this.serializedWindow.getInstanceID = (0, _src3.memoizePromise)(this.serializedWindow.getInstanceID); | ||
this.send = send; | ||
} | ||
ProxyWindow.prototype.isPopup = function isPopup() { | ||
return this.getType() === WINDOW_TYPE.POPUP; | ||
}; | ||
getType() { | ||
return this.serializedWindow.type; | ||
} | ||
ProxyWindow.prototype.isIframe = function isIframe() { | ||
return this.getType() === WINDOW_TYPE.IFRAME; | ||
}; | ||
isPopup() { | ||
return this.getType() === _src.WINDOW_TYPE.POPUP; | ||
} | ||
ProxyWindow.prototype.setLocation = function setLocation(href) { | ||
var _this = this; | ||
isIframe() { | ||
return this.getType() === _src.WINDOW_TYPE.IFRAME; | ||
} | ||
return ZalgoPromise['try'](function () { | ||
if (_this.actualWindow) { | ||
_this.actualWindow.location = href; | ||
} else { | ||
return _this.serializedWindow.setLocation(href); | ||
} | ||
}).then(function () { | ||
return _this; | ||
}); | ||
}; | ||
setLocation(href) { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (this.actualWindow) { | ||
this.actualWindow.location = href; | ||
} else { | ||
return this.serializedWindow.setLocation(href); | ||
} | ||
}).then(() => this); | ||
} | ||
ProxyWindow.prototype.setName = function setName(name) { | ||
var _this2 = this; | ||
setName(name) { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (this.actualWindow) { | ||
if (!(0, _src.isSameDomain)(this.actualWindow)) { | ||
throw new Error(`Can not set name for window on different domain`); | ||
} // $FlowFixMe | ||
return ZalgoPromise['try'](function () { | ||
if (_this2.actualWindow) { | ||
if (!isSameDomain(_this2.actualWindow)) { | ||
throw new Error('Can not set name for window on different domain'); | ||
} | ||
// $FlowFixMe | ||
_this2.actualWindow.name = name; | ||
// $FlowFixMe | ||
if (_this2.actualWindow.frameElement) { | ||
// $FlowFixMe | ||
_this2.actualWindow.frameElement.setAttribute('name', name); | ||
} | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
var _require = require('../bridge'), | ||
linkWindow = _require.linkWindow; | ||
this.actualWindow.name = name; // $FlowFixMe | ||
linkWindow({ win: _this2.actualWindow, name: name }); | ||
} | ||
} else { | ||
return _this2.serializedWindow.setName(name); | ||
} | ||
}).then(function () { | ||
return _this2; | ||
}); | ||
}; | ||
if (this.actualWindow.frameElement) { | ||
// $FlowFixMe | ||
this.actualWindow.frameElement.setAttribute('name', name); | ||
} | ||
ProxyWindow.prototype.close = function close() { | ||
var _this3 = this; | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
(0, _bridge.linkWindow)({ | ||
win: this.actualWindow, | ||
name | ||
}); | ||
} | ||
} else { | ||
return this.serializedWindow.setName(name); | ||
} | ||
}).then(() => this); | ||
} | ||
return ZalgoPromise['try'](function () { | ||
if (_this3.actualWindow) { | ||
_this3.actualWindow.close(); | ||
} else { | ||
return _this3.serializedWindow.close(); | ||
} | ||
}).then(function () { | ||
return _this3; | ||
}); | ||
}; | ||
close() { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (this.actualWindow) { | ||
this.actualWindow.close(); | ||
} else { | ||
return this.serializedWindow.close(); | ||
} | ||
}).then(() => this); | ||
} | ||
ProxyWindow.prototype.focus = function focus() { | ||
var _this4 = this; | ||
focus() { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (this.actualWindow) { | ||
this.actualWindow.focus(); | ||
} | ||
return ZalgoPromise['try'](function () { | ||
if (_this4.actualWindow) { | ||
_this4.actualWindow.focus(); | ||
} | ||
return _this4.serializedWindow.focus(); | ||
}).then(function () { | ||
return _this4; | ||
}); | ||
}; | ||
return this.serializedWindow.focus(); | ||
}).then(() => this); | ||
} | ||
ProxyWindow.prototype.isClosed = function isClosed() { | ||
var _this5 = this; | ||
isClosed() { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (this.actualWindow) { | ||
return (0, _src.isWindowClosed)(this.actualWindow); | ||
} else { | ||
return this.serializedWindow.isClosed(); | ||
} | ||
}); | ||
} | ||
return ZalgoPromise['try'](function () { | ||
if (_this5.actualWindow) { | ||
return isWindowClosed(_this5.actualWindow); | ||
} else { | ||
return _this5.serializedWindow.isClosed(); | ||
} | ||
}); | ||
}; | ||
getWindow() { | ||
return this.actualWindow; | ||
} | ||
ProxyWindow.prototype.getWindow = function getWindow() { | ||
return this.actualWindow; | ||
}; | ||
setWindow(win) { | ||
this.actualWindow = win; | ||
this.actualWindowPromise.resolve(win); | ||
} | ||
ProxyWindow.prototype.setWindow = function setWindow(win) { | ||
this.actualWindow = win; | ||
this.actualWindowPromise.resolve(win); | ||
}; | ||
awaitWindow() { | ||
return this.actualWindowPromise; | ||
} | ||
ProxyWindow.prototype.awaitWindow = function awaitWindow() { | ||
return this.actualWindowPromise; | ||
}; | ||
matchWindow(win) { | ||
return _src2.ZalgoPromise.try(() => { | ||
if (this.actualWindow) { | ||
return win === this.actualWindow; | ||
} | ||
ProxyWindow.prototype.matchWindow = function matchWindow(win) { | ||
var _this6 = this; | ||
return _src2.ZalgoPromise.all([this.getInstanceID(), (0, _lib.getWindowInstanceID)(win, { | ||
send: this.send | ||
})]).then(([proxyInstanceID, knownWindowInstanceID]) => { | ||
const match = proxyInstanceID === knownWindowInstanceID; | ||
return ZalgoPromise['try'](function () { | ||
if (_this6.actualWindow) { | ||
return win === _this6.actualWindow; | ||
} | ||
if (match) { | ||
this.setWindow(win); | ||
} | ||
return ZalgoPromise.all([_this6.getInstanceID(), getWindowInstanceID(win)]).then(function (_ref) { | ||
var proxyInstanceID = _ref[0], | ||
knownWindowInstanceID = _ref[1]; | ||
return match; | ||
}); | ||
}); | ||
} | ||
var match = proxyInstanceID === knownWindowInstanceID; | ||
unwrap() { | ||
return this.actualWindow || this; | ||
} | ||
if (match) { | ||
_this6.setWindow(win); | ||
} | ||
getInstanceID() { | ||
if (this.actualWindow) { | ||
return (0, _lib.getWindowInstanceID)(this.actualWindow, { | ||
send: this.send | ||
}); | ||
} else { | ||
return this.serializedWindow.getInstanceID(); | ||
} | ||
} | ||
return match; | ||
}); | ||
}); | ||
}; | ||
serialize() { | ||
return this.serializedWindow; | ||
} | ||
ProxyWindow.prototype.unwrap = function unwrap() { | ||
return this.actualWindow || this; | ||
}; | ||
shouldClean() { | ||
return this.actualWindow && (0, _src.isWindowClosed)(this.actualWindow); | ||
} | ||
ProxyWindow.prototype.getInstanceID = function getInstanceID() { | ||
if (this.actualWindow) { | ||
return getWindowInstanceID(this.actualWindow); | ||
} else { | ||
return this.serializedWindow.getInstanceID(); | ||
} | ||
}; | ||
static unwrap(win) { | ||
return ProxyWindow.isProxyWindow(win) // $FlowFixMe | ||
? win.unwrap() : win; | ||
} | ||
ProxyWindow.prototype.serialize = function serialize() { | ||
return this.serializedWindow; | ||
}; | ||
static serialize(win, { | ||
send | ||
}) { | ||
cleanupProxyWindows(); | ||
return ProxyWindow.toProxyWindow(win, { | ||
send | ||
}).serialize(); | ||
} | ||
ProxyWindow.prototype.shouldClean = function shouldClean() { | ||
return this.actualWindow && isWindowClosed(this.actualWindow); | ||
}; | ||
static deserialize(serializedWindow, { | ||
on, | ||
send | ||
}) { | ||
cleanupProxyWindows(); | ||
return (0, _global.globalStore)('idToProxyWindow').getOrSet(serializedWindow.id, () => { | ||
return new ProxyWindow(serializedWindow, null, { | ||
on, | ||
send | ||
}); | ||
}); | ||
} | ||
ProxyWindow.unwrap = function unwrap(win) { | ||
return ProxyWindow.isProxyWindow(win) | ||
// $FlowFixMe | ||
? win.unwrap() : win; | ||
}; | ||
static isProxyWindow(obj) { | ||
// $FlowFixMe | ||
return Boolean(obj && !(0, _src.isWindow)(obj) && obj.isProxyWindow); | ||
} | ||
ProxyWindow.serialize = function serialize(win) { | ||
cleanupProxyWindows(); | ||
static toProxyWindow(win, { | ||
send | ||
}) { | ||
cleanupProxyWindows(); | ||
return ProxyWindow.toProxyWindow(win).serialize(); | ||
}; | ||
if (ProxyWindow.isProxyWindow(win)) { | ||
// $FlowFixMe | ||
return win; | ||
} // $FlowFixMe | ||
ProxyWindow.deserialize = function deserialize(serializedWindow) { | ||
cleanupProxyWindows(); | ||
return idToProxyWindow.getOrSet(serializedWindow.id, function () { | ||
return new ProxyWindow(serializedWindow); | ||
}); | ||
}; | ||
ProxyWindow.isProxyWindow = function isProxyWindow(obj) { | ||
return (0, _global.windowStore)('winToProxyWindow').getOrSet(win, () => { | ||
const id = (0, _src3.uniqueID)(); | ||
return (0, _global.globalStore)('idToProxyWindow').set(id, new ProxyWindow({ | ||
id, | ||
// $FlowFixMe | ||
return Boolean(obj && !isWindow(obj) && obj.isProxyWindow); | ||
}; | ||
type: (0, _src.getOpener)(win) ? _src.WINDOW_TYPE.POPUP : _src.WINDOW_TYPE.IFRAME, | ||
// $FlowFixMe | ||
getInstanceID: () => (0, _lib.getWindowInstanceID)(win, { | ||
send | ||
}), | ||
close: () => _src2.ZalgoPromise.try(() => { | ||
win.close(); | ||
}), | ||
focus: () => _src2.ZalgoPromise.try(() => { | ||
win.focus(); | ||
}), | ||
isClosed: () => _src2.ZalgoPromise.try(() => { | ||
// $FlowFixMe | ||
return (0, _src.isWindowClosed)(win); | ||
}), | ||
setLocation: href => _src2.ZalgoPromise.try(() => { | ||
// $FlowFixMe | ||
if ((0, _src.isSameDomain)(win)) { | ||
try { | ||
if (win.location && typeof win.location.replace === 'function') { | ||
// $FlowFixMe | ||
win.location.replace(href); | ||
return; | ||
} | ||
} catch (err) {// pass | ||
} | ||
} // $FlowFixMe | ||
ProxyWindow.toProxyWindow = function toProxyWindow(win) { | ||
cleanupProxyWindows(); | ||
if (ProxyWindow.isProxyWindow(win)) { | ||
win.location = href; | ||
}), | ||
setName: name => _src2.ZalgoPromise.try(() => { | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
// $FlowFixMe | ||
return win; | ||
} | ||
(0, _bridge.linkWindow)({ | ||
win, | ||
name | ||
}); | ||
} // $FlowFixMe | ||
// $FlowFixMe | ||
return winToProxyWindow.getOrSet(win, function () { | ||
var id = uniqueID(); | ||
return idToProxyWindow.set(id, new ProxyWindow({ | ||
id: id, | ||
// $FlowFixMe | ||
type: getOpener(win) ? WINDOW_TYPE.POPUP : WINDOW_TYPE.IFRAME, | ||
getInstanceID: function getInstanceID() { | ||
return getWindowInstanceID(win); | ||
}, | ||
close: function close() { | ||
return ZalgoPromise['try'](function () { | ||
win.close(); | ||
}); | ||
}, | ||
focus: function focus() { | ||
return ZalgoPromise['try'](function () { | ||
win.focus(); | ||
}); | ||
}, | ||
isClosed: function isClosed() { | ||
return ZalgoPromise['try'](function () { | ||
// $FlowFixMe | ||
return isWindowClosed(win); | ||
}); | ||
}, | ||
setLocation: function setLocation(href) { | ||
return ZalgoPromise['try'](function () { | ||
// $FlowFixMe | ||
if (isSameDomain(win)) { | ||
try { | ||
if (win.location && typeof win.location.replace === 'function') { | ||
// $FlowFixMe | ||
win.location.replace(href); | ||
return; | ||
} | ||
} catch (err) { | ||
// pass | ||
} | ||
} | ||
win.name = name; | ||
}) // $FlowFixMe | ||
// $FlowFixMe | ||
win.location = href; | ||
}); | ||
}, | ||
setName: function setName(name) { | ||
return ZalgoPromise['try'](function () { | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
var _require2 = require('../bridge'), | ||
linkWindow = _require2.linkWindow; | ||
// $FlowFixMe | ||
}, win, { | ||
send | ||
})); | ||
}); | ||
} | ||
} | ||
linkWindow({ win: win, name: name }); | ||
} | ||
// $FlowFixMe | ||
win.name = name; | ||
}); | ||
} | ||
// $FlowFixMe | ||
}, win)); | ||
}); | ||
}; | ||
exports.ProxyWindow = ProxyWindow; | ||
return ProxyWindow; | ||
}(); | ||
export function serializeWindow(destination, domain, win) { | ||
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW, ProxyWindow.serialize(win)); | ||
function serializeWindow(destination, domain, win, { | ||
send | ||
}) { | ||
return (0, _src4.serializeType)(_conf.SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW, ProxyWindow.serialize(win, { | ||
send | ||
})); | ||
} | ||
export function deserializeWindow(source, origin, win) { | ||
return ProxyWindow.deserialize(win); | ||
function deserializeWindow(source, origin, win, { | ||
on, | ||
send | ||
}) { | ||
return ProxyWindow.deserialize(win, { | ||
on, | ||
send | ||
}); | ||
} |
@@ -1,2 +0,2 @@ | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("postRobot",[],e):"object"==typeof exports?exports.postRobot=e():n.postRobot=e()}("undefined"!=typeof self?self:this,function(){return function(n){var e={};function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:r})},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=13)}([function(n,e,t){"use strict";var r=t(14);t.d(e,"getActualDomain",function(){return r.a}),t.d(e,"getAncestor",function(){return r.b}),t.d(e,"getDomain",function(){return r.c}),t.d(e,"getDomainFromUrl",function(){return r.d}),t.d(e,"getFrameByName",function(){return r.e}),t.d(e,"getOpener",function(){return r.f}),t.d(e,"getParent",function(){return r.g}),t.d(e,"getUserAgent",function(){return r.h}),t.d(e,"isActuallySameDomain",function(){return r.i}),t.d(e,"isAncestor",function(){return r.j}),t.d(e,"isOpener",function(){return r.k}),t.d(e,"isSameDomain",function(){return r.l}),t.d(e,"isSameTopWindow",function(){return r.m}),t.d(e,"isWindow",function(){return r.n}),t.d(e,"isWindowClosed",function(){return r.o}),t.d(e,"linkFrameWindow",function(){return r.p}),t.d(e,"matchDomain",function(){return r.q}),t.d(e,"normalizeMockUrl",function(){return r.r}),t.d(e,"stringifyDomainPattern",function(){return r.s});var o=t(15);t.n(o),t.o(o,"WINDOW_TYPE")&&t.d(e,"WINDOW_TYPE",function(){return o.WINDOW_TYPE});var i=t(9);t.d(e,"WINDOW_TYPE",function(){return i.c})},function(n,e,t){"use strict";var r,o={REQUEST:"postrobot_message_request",RESPONSE:"postrobot_message_response",ACK:"postrobot_message_ack"},i={SUCCESS:"success",ERROR:"error"},a={METHOD:"postrobot_method",HELLO:"postrobot_hello",OPEN_TUNNEL:"postrobot_open_tunnel"},u={POSTROBOT:"__postRobot__"},c={POST_MESSAGE:"postrobot_post_message",BRIDGE:"postrobot_bridge",GLOBAL:"postrobot_global"},s={MOCK:"mock:",FILE:"file:"},f={CROSS_DOMAIN_ZALGO_PROMISE:"cross_domain_zalgo_promise",CROSS_DOMAIN_FUNCTION:"cross_domain_function",CROSS_DOMAIN_WINDOW:"cross_domain_window"},d={BRIDGE_TIMEOUT:5e3,CHILD_WINDOW_TIMEOUT:5e3,ACK_TIMEOUT:2e3,ACK_TIMEOUT_KNOWN:1e4,RES_TIMEOUT:-1,ALLOWED_POST_MESSAGE_METHODS:(r={},r[c.POST_MESSAGE]=!0,r[c.BRIDGE]=!0,r[c.GLOBAL]=!0,r)};t.d(e,"b",function(){return d}),t.d(e,"e",function(){return o}),t.d(e,"c",function(){return i}),t.d(e,"d",function(){return a}),t.d(e,"j",function(){return u}),t.d(e,"g",function(){return c}),t.d(e,"f",function(){return s}),t.d(e,"a",function(){return"__postrobot_bridge__"}),t.d(e,!1,function(){return"__postrobot_proxy__"}),t.d(e,"i",function(){return"*"}),t.d(e,"h",function(){return f})},function(n,e,t){"use strict";function r(n){try{if(!n)return!1;if("undefined"!=typeof Promise&&n instanceof Promise)return!0;if("undefined"!=typeof window&&window.Window&&n instanceof window.Window)return!1;if("undefined"!=typeof window&&window.constructor&&n instanceof window.constructor)return!1;var e={}.toString;if(e){var t=e.call(n);if("[object Window]"===t||"[object global]"===t||"[object DOMWindow]"===t)return!1}if("function"==typeof n.then)return!0}catch(n){return!1}return!1}function o(){var n=void 0;if("undefined"!=typeof window)n=window;else{if("undefined"==typeof window)throw new TypeError("Can not find global");n=window}var e=n.__zalgopromise__=n.__zalgopromise__||{};return e.flushPromises=e.flushPromises||[],e.activeCount=e.activeCount||0,e.possiblyUnhandledPromiseHandlers=e.possiblyUnhandledPromiseHandlers||[],e.dispatchedErrors=e.dispatchedErrors||[],e}var i=function(){function n(e){var t=this;if(function(e,t){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this),this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],e){var r=void 0,o=void 0,i=!1,a=!1,u=!1;try{e(function(n){u?t.resolve(n):(i=!0,r=n)},function(n){u?t.reject(n):(a=!0,o=n)})}catch(n){return void this.reject(n)}u=!0,i?this.resolve(r):a&&this.reject(o)}}return n.prototype.resolve=function(n){if(this.resolved||this.rejected)return this;if(r(n))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=n,this.dispatch(),this},n.prototype.reject=function(n){var e=this;if(this.resolved||this.rejected)return this;if(r(n))throw new Error("Can not reject promise with another promise");if(!n){var t=n&&"function"==typeof n.toString?n.toString():Object.prototype.toString.call(n);n=new Error("Expected reject to be called with Error, got "+t)}return this.rejected=!0,this.error=n,this.errorHandled||setTimeout(function(){e.errorHandled||function(n,e){if(-1===o().dispatchedErrors.indexOf(n)){o().dispatchedErrors.push(n),setTimeout(function(){throw n},1);for(var t=0;t<o().possiblyUnhandledPromiseHandlers.length;t++)o().possiblyUnhandledPromiseHandlers[t](n,e)}}(n,e)},1),this.dispatch(),this},n.prototype.asyncReject=function(n){return this.errorHandled=!0,this.reject(n),this},n.prototype.dispatch=function(){var e=this,t=this.dispatching,i=this.resolved,a=this.rejected,u=this.handlers;if(!t&&(i||a)){this.dispatching=!0,o().activeCount+=1;for(var c=function(t){var o=u[t],c=o.onSuccess,s=o.onError,f=o.promise,d=void 0;if(i)try{d=c?c(e.value):e.value}catch(n){return f.reject(n),"continue"}else if(a){if(!s)return f.reject(e.error),"continue";try{d=s(e.error)}catch(n){return f.reject(n),"continue"}}d instanceof n&&(d.resolved||d.rejected)?(d.resolved?f.resolve(d.value):f.reject(d.error),d.errorHandled=!0):r(d)?d instanceof n&&(d.resolved||d.rejected)?d.resolved?f.resolve(d.value):f.reject(d.error):d.then(function(n){f.resolve(n)},function(n){f.reject(n)}):f.resolve(d)},s=0;s<u.length;s++)c(s);u.length=0,this.dispatching=!1,o().activeCount-=1,0===o().activeCount&&n.flushQueue()}},n.prototype.then=function(e,t){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.then expected a function for success handler");if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.then expected a function for error handler");var r=new n;return this.handlers.push({promise:r,onSuccess:e,onError:t}),this.errorHandled=!0,this.dispatch(),r},n.prototype.catch=function(n){return this.then(void 0,n)},n.prototype.finally=function(e){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.finally expected a function");return this.then(function(t){return n.try(e).then(function(){return t})},function(t){return n.try(e).then(function(){throw t})})},n.prototype.timeout=function(n,e){var t=this;if(this.resolved||this.rejected)return this;var r=setTimeout(function(){t.resolved||t.rejected||t.reject(e||new Error("Promise timed out after "+n+"ms"))},n);return this.then(function(n){return clearTimeout(r),n})},n.prototype.toPromise=function(){if("undefined"==typeof Promise)throw new TypeError("Could not find Promise");return Promise.resolve(this)},n.resolve=function(e){return e instanceof n?e:r(e)?new n(function(n,t){return e.then(n,t)}):(new n).resolve(e)},n.reject=function(e){return(new n).reject(e)},n.asyncReject=function(e){return(new n).asyncReject(e)},n.all=function(e){var t=new n,o=e.length,i=[];if(!o)return t.resolve(i),t;for(var a=function(a){var u=e[a];if(u instanceof n){if(u.resolved)return i[a]=u.value,o-=1,"continue"}else if(!r(u))return i[a]=u,o-=1,"continue";n.resolve(u).then(function(n){i[a]=n,0==(o-=1)&&t.resolve(i)},function(n){t.reject(n)})},u=0;u<e.length;u++)a(u);return 0===o&&t.resolve(i),t},n.hash=function(e){var t={};return n.all(Object.keys(e).map(function(r){return n.resolve(e[r]).then(function(n){t[r]=n})})).then(function(){return t})},n.map=function(e,t){return n.all(e.map(t))},n.onPossiblyUnhandledException=function(n){return function(n){return o().possiblyUnhandledPromiseHandlers.push(n),{cancel:function(){o().possiblyUnhandledPromiseHandlers.splice(o().possiblyUnhandledPromiseHandlers.indexOf(n),1)}}}(n)},n.try=function(e,t,r){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.try expected a function");var o=void 0;try{o=e.apply(t,r||[])}catch(e){return n.reject(e)}return n.resolve(o)},n.delay=function(e){return new n(function(n){setTimeout(n,e)})},n.isPromise=function(e){return!!(e&&e instanceof n)||r(e)},n.flush=function(){var e=new n;return o().flushPromises.push(e),0===o().activeCount&&n.flushQueue(),e},n.flushQueue=function(){var n=o().flushPromises;o().flushPromises=[];for(var e=0,t=null==n?0:n.length;e<t;e++)n[e].resolve()},n}();t.d(e,"a",function(){return i})},function(n,e,t){"use strict";t(10);var r=t(11);t.d(e,"addEventListener",function(){return r.a}),t(16),t(17),t(12);var o=t(6);t.d(e,"getOrSet",function(){return o.d}),t.d(e,"isRegex",function(){return o.f}),t.d(e,"memoizePromise",function(){return o.h}),t.d(e,"noop",function(){return o.i}),t.d(e,"once",function(){return o.j}),t.d(e,"safeInterval",function(){return o.m}),t.d(e,"stringifyError",function(){return o.o}),t.d(e,"uniqueID",function(){return o.q}),t.d(e,"weakMapMemoize",function(){return o.r}),t.d(e,"weakMapMemoizePromise",function(){return o.s}),t(18);var i=t(19);t.n(i),t(20),t(21),t(22)},function(n,e,t){"use strict";t.d(e,"a",function(){return a}),e.c=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c;function t(n){return u.getOrSet(n,e)}return{has:function(e){return t(e).hasOwnProperty(n)},get:function(e,r){var o=t(e);return o.hasOwnProperty(n)?o[n]:r},set:function(e,r){return t(e)[n]=r,r},del:function(e){delete t(e)[n]},getOrSet:function(e,r){var o=t(e);if(o.hasOwnProperty(n))return o[n];var i=r();return o[n]=i,i}}},e.b=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c,t=Object(o.getOrSet)(a,n,e);return{has:function(n){return t.hasOwnProperty(n)},get:function(n,e){return t.hasOwnProperty(n)?t[n]:e},set:function(n,e){return t[n]=e,e},del:function(n){delete t[n]},getOrSet:function(n,e){if(t.hasOwnProperty(n))return t[n];var r=e();return t[n]=r,r},reset:function(){t=e()},keys:function(){return Object.keys(t)}}},t(0);var r=t(8),o=t(3),i=t(1),a=window[i.j.POSTROBOT]=window[i.j.POSTROBOT]||{},u=a.windowStore=a.windowStore||new r.a,c=function(){return{}}},function(n,e,t){"use strict";var r=t(0),o=t(2),i=t(3),a=t(1),u=t(4);u.a.instanceID=u.a.instanceID||Object(i.uniqueID)();var c=Object(u.c)("helloPromises");function s(n){return c.getOrSet(n,function(){return new o.a})}var f=Object(i.once)(function(){u.a.on(a.d.HELLO,{domain:a.i},function(n){var e=n.source,t=n.origin;return s(e).resolve({win:e,domain:t}),{instanceID:u.a.instanceID}})});function d(n){return u.a.send(n,a.d.HELLO,{instanceID:u.a.instanceID},{domain:a.i,timeout:-1}).then(function(e){var t=e.origin,r=e.data.instanceID;return s(n).resolve({win:n,domain:t}),{win:n,domain:t,instanceID:r}})}var l=Object(i.weakMapMemoizePromise)(function(n){return d(n).then(function(n){return n.instanceID})});function w(){f();var n=Object(r.getAncestor)();n&&d(n).catch(i.noop)}function h(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Window",r=s(n);return-1!==e&&(r=r.timeout(e,new Error(t+" did not load after "+e+"ms"))),r}function m(){return!!Object(r.getUserAgent)(window).match(/MSIE|rv:11|trident|edge\/12|edge\/13/i)}var p=Object(u.c)("knownWindows");function g(n){p.set(n,!0)}function v(n){return p.get(n,!1)}t.d(e,"g",function(){return d}),t.d(e,"b",function(){return l}),t.d(e,"c",function(){return w}),t.d(e,"a",function(){return h}),t.d(e,"f",function(){return m}),t.d(e,"e",function(){return g}),t.d(e,"d",function(){return v})},function(n,e,t){"use strict";e.q=a,e.c=function(){if("undefined"!=typeof window)return window;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("No global found")},e.g=function(n){var e=this,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new o.a;function i(){for(var e=arguments.length,o=Array(e),i=0;i<e;i++)o[i]=arguments[i];var a=r.getOrSet(t.thisNamespace?this:n,function(){return{}}),u=c(o),s=t.time;if(a[u]&&s&&Date.now()-a[u].time<s&&delete a[u],a[u])return a[u].value;var f=Date.now(),d=n.apply(this,arguments);return a[u]={time:f,value:d},a[u].value}return i.reset=function(){r.delete(t.thisNamespace?e:n)},t.name&&(i.displayName=t.name+":memoized"),i},e.h=function(n){var e={};function t(){for(var t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];var i=c(r);return e.hasOwnProperty(i)?e[i]:(e[i]=n.apply(this,arguments).finally(function(){delete e[i]}),e[i])}return t.reset=function(){e={}},t},e.k=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};function t(){return r.a.try(n,this,arguments)}return e.name&&(t.displayName=e.name+":promisified"),t},e.e=function(n,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=n.__inline_memoize_cache__=n.__inline_memoize_cache__||{},o=c(t);return r.hasOwnProperty(o)?r[o]:r[o]=e.apply(void 0,t)},e.i=function(){},e.j=function(n){var e=!1;return function(){if(!e)return e=!0,n.apply(this,arguments)}},e.o=function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(t>=3)return"stringifyError stack overflow";try{if(!e)return"<unknown error: "+Object.prototype.toString.call(e)+">";if("string"==typeof e)return e;if(e instanceof Error){var r=e&&e.stack,o=e&&e.message;if(r&&o)return-1!==r.indexOf(o)?r:o+"\n"+r;if(r)return r;if(o)return o}return"function"==typeof e.toString?e.toString():Object.prototype.toString.call(e)}catch(e){return"Error while stringifying error: "+n(e,t+1)}},e.n=function(n){return"string"==typeof n?n:n&&"function"==typeof n.toString?n.toString():Object.prototype.toString.call(n)},e.b=function(n,e){if(!e)return n;if(Object.assign)return Object.assign(n,e);for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return n},e.m=function(n,e){var t=void 0;return function r(){t=setTimeout(function(){n(),r()},e)}(),{cancel:function(){clearTimeout(t)}}},e.a=function(n){return n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()},e.f=function(n){return"[object RegExp]"===Object.prototype.toString.call(n)},t.d(e,"r",function(){return s}),t.d(e,"s",function(){return f}),e.d=function(n,e,t){if(n.hasOwnProperty(e))return n[e];var r=t();return n[e]=r,r},e.p=function(n){var e=void 0,t=void 0;try{e=n()}catch(n){t=n}return{result:e,error:t}},e.l=function(n,e){var t=n.indexOf(e);-1!==t&&n.splice(t,1)};var r=t(2),o=t(8),i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function a(){var n="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,function(){return n.charAt(Math.floor(Math.random()*n.length))})+"_"+function(n){if("function"==typeof btoa)return btoa(n);if("undefined"!=typeof Buffer)return Buffer.from(n,"utf8").toString("base64");throw new Error("Can not find window.btoa or Buffer")}((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}var u=void 0;function c(n){try{return JSON.stringify(Array.prototype.slice.call(n),function(n,e){return"function"==typeof e?"memoize["+function(n){if(u=u||new o.a,null===n||void 0===n||"object"!==(void 0===n?"undefined":i(n))&&"function"!=typeof n)throw new Error("Invalid object");var e=u.get(n);return e||(e=(void 0===n?"undefined":i(n))+":"+a(),u.set(n,e)),e}(e)+"]":e})}catch(n){throw new Error("Arguments not serializable -- can not be used to memoize")}}var s=function(n){var e=new o.a;return function(t){var r=this;return e.getOrSet(t,function(){return n.call(r,t)})}},f=function(n){var e=new o.a;return function(t){var r=this;return e.getOrSet(t,function(){return n.call(r,t).finally(function(){e.delete(t)})})}}},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=t(2),o=t(0),i=t(3),a=t(1),u=t(4),c=Object(u.b)("tunnelWindows");function s(){return!!Object(o.getUserAgent)(window).match(/MSIE|trident|edge\/12|edge\/13/i)}function f(n){return!Object(o.isSameTopWindow)(window,n)}function d(n,e){if(n){if(Object(o.getDomain)()!==Object(o.getDomainFromUrl)(n))return!0}else if(e&&!Object(o.isSameDomain)(e))return!0;return!1}function l(n){var e=n.win,t=n.domain;return!(!s()||t&&!d(t,e)||e&&!f(e))}function w(n){var e=(n=n||Object(o.getDomainFromUrl)(n)).replace(/[^a-zA-Z0-9]+/g,"_");return a.a+"_"+e}function h(){return Boolean(window.name&&window.name===w(Object(o.getDomain)()))}u.a.openTunnelToParent=function(n){var e=n.name,t=n.source,r=n.canary,s=n.sendMessage,f=Object(o.getParent)(window);if(!f)throw new Error("No parent window found to open tunnel to");var d=function(n){var e=n.name,t=n.source,r=n.canary,a=n.sendMessage;!function(){for(var n=0,e=c.keys(),t=null==e?0:e.length;n<t;n++){var r=e[n],a=c[r];try{Object(i.noop)(a.source)}catch(n){c.del(r);continue}Object(o.isWindowClosed)(a.source)&&c.del(r)}}();var u=Object(i.uniqueID)();return c.set(u,{name:e,source:t,canary:r,sendMessage:a}),u}({name:e,source:t,canary:r,sendMessage:s});return u.a.send(f,a.d.OPEN_TUNNEL,{name:e,sendMessage:function(){var n=c.get(d);try{Object(i.noop)(n&&n.source)}catch(n){return void c.del(d)}if(n&&n.source&&!Object(o.isWindowClosed)(n.source)){try{n.canary()}catch(n){return}n.sendMessage.apply(this,arguments)}}},{domain:a.i})};var m=new r.a(function(n){if(window.document&&window.document.body)return n(window.document.body);var e=setInterval(function(){if(window.document&&window.document.body)return clearInterval(e),n(window.document.body)},10)}),p=Object(u.c)("remoteWindows");function g(n){p.getOrSet(n,function(){return new r.a})}function v(n){var e=p.get(n);if(!e)throw new Error("Remote window not found");return e}function y(n,e,t){v(n).resolve(function(r,i,a){if(r!==n)throw new Error("Remote window does not match window");if(!Object(o.matchDomain)(i,e))throw new Error("Remote domain "+i+" does not match domain "+e);t(a)})}function O(n,e){v(n).reject(e).catch(i.noop)}function b(n,e,t){var r=Object(o.isOpener)(window,n),i=Object(o.isOpener)(n,window);if(!r&&!i)throw new Error("Can only send messages to and from parent and popup windows");return v(n).then(function(r){return r(n,e,t)})}var E=Object(i.weakMapMemoize)(function(n){return r.a.try(function(){try{var e=Object(o.getFrameByName)(n,w(Object(o.getDomain)()));if(!e)return;return Object(o.isSameDomain)(e)&&e[a.j.POSTROBOT]?e:new r.a(function(n){var t=void 0,r=void 0;t=setInterval(function(){if(e&&Object(o.isSameDomain)(e)&&e[a.j.POSTROBOT])return clearInterval(t),clearTimeout(r),n(e)},100),r=setTimeout(function(){return clearInterval(t),n()},2e3)})}catch(n){}})});function j(){return r.a.try(function(){var n=Object(o.getOpener)(window);if(n&&l({win:n}))return g(n),E(n).then(function(e){return e?window.name?e[a.j.POSTROBOT].openTunnelToParent({name:window.name,source:window,canary:function(){},sendMessage:function(n){try{Object(i.noop)(window)}catch(n){return}if(window&&!window.closed)try{u.a.receiveMessage({data:n,origin:this.origin,source:this.source})}catch(n){r.a.reject(n)}}}).then(function(e){var t=e.source,r=e.origin,o=e.data;if(t!==n)throw new Error("Source does not match opener");y(t,r,o.sendMessage)}).catch(function(e){throw O(n,e),e}):O(n,new Error("Can not register with opener: window does not have a name")):O(n,new Error("Can not register with opener: no bridge found in opener"))})})}var _=t(5),S=Object(u.b)("bridges"),W=Object(u.b)("bridgeFrames"),D=Object(u.b)("popupWindowsByName"),T=Object(u.c)("popupWindowsByWin");function I(n,e){return S.has(e||Object(o.getDomainFromUrl)(n))}function P(n,e){return e=e||Object(o.getDomainFromUrl)(n),S.getOrSet(e,function(){return r.a.try(function(){if(Object(o.getDomain)()===e)throw new Error("Can not open bridge on the same domain as current domain: "+e);var t=w(e);if(Object(o.getFrameByName)(window,t))throw new Error("Frame with name "+t+" already exists on page");var i=function(n,e){var t=document.createElement("iframe");return t.setAttribute("name",n),t.setAttribute("id",n),t.setAttribute("style","display: none; margin: 0; padding: 0; border: 0px none; overflow: hidden;"),t.setAttribute("frameborder","0"),t.setAttribute("border","0"),t.setAttribute("scrolling","no"),t.setAttribute("allowTransparency","true"),t.setAttribute("tabindex","-1"),t.setAttribute("hidden","true"),t.setAttribute("title",""),t.setAttribute("role","presentation"),t.src=e,t}(t,n);return W.set(e,i),m.then(function(t){t.appendChild(i);var o=i.contentWindow;return function(n,e){u.a.on(a.d.OPEN_TUNNEL,{window:n,domain:e},function(n){var t=n.origin,o=n.data;if(t!==e)throw new Error("Domain "+e+" does not match origin "+t);if(!o.name)throw new Error("Register window expected to be passed window name");if(!o.sendMessage)throw new Error("Register window expected to be passed sendMessage method");if(!D.has(o.name))throw new Error("Window with name "+o.name+" does not exist, or was not opened by this window");if(!D.get(o.name).domain)throw new Error("We do not have a registered domain for window "+o.name);if(D.get(o.name).domain!==t)throw new Error("Message origin "+t+" does not matched registered window origin "+D.get(o.name).domain);return y(D.get(o.name).win,e,o.sendMessage),{sendMessage:function(n){if(window&&!window.closed){var e=D.get(o.name);if(e)try{u.a.receiveMessage({data:n,origin:e.domain,source:e.win})}catch(n){r.a.reject(n)}}}}})}(o,e),new r.a(function(n,e){i.onload=n,i.onerror=e}).then(function(){return Object(_.a)(o,a.b.BRIDGE_TIMEOUT,"Bridge "+n)}).then(function(){return o})})})})}function R(n){for(var e=n.win,t=n.name,r=n.domain,i=0,a=D.keys(),u=null==a?0:a.length;i<u;i++){var c=a[i];Object(o.isWindowClosed)(D.get(c).win)&&D.del(c)}var s=T.getOrSet(e,function(){return t?D.getOrSet(t,function(){return{win:e,name:t}}):{win:e}});if(s.win&&s.win!==e)throw new Error("Different window already linked for window: "+(t||"undefined"));if(t){if(s.name&&s.name!==t)throw new Error("Different window already linked for name "+t+": "+s.name);s.name=t,D.set(t,s)}return r&&(s.domain=r,g(e)),T.set(e,s),s}function A(n,e){R({win:n,domain:Object(o.getDomainFromUrl)(e)})}var M=window.open;function N(){for(var n=0,e=W.keys(),t=null==e?0:e.length;n<t;n++){var r=e[n],o=W.get(r);o&&o.parentNode&&o.parentNode.removeChild(o)}W.reset(),S.reset()}window.open=function(n,e,t,r){var i=M.call(this,Object(o.normalizeMockUrl)(n),e,t,r);return i?(R({win:i,name:e,domain:n?Object(o.getDomainFromUrl)(n):null}),i):i},t.d(e,"openTunnelToOpener",function(){return j}),t.d(e,"needsBridgeForBrowser",function(){return s}),t.d(e,"needsBridgeForWin",function(){return f}),t.d(e,"needsBridgeForDomain",function(){return d}),t.d(e,"needsBridge",function(){return l}),t.d(e,"getBridgeName",function(){return w}),t.d(e,"isBridge",function(){return h}),t.d(e,"documentBodyReady",function(){return m}),t.d(e,"registerRemoteWindow",function(){return g}),t.d(e,"findRemoteWindow",function(){return v}),t.d(e,"registerRemoteSendMessage",function(){return y}),t.d(e,"rejectRemoteSendMessage",function(){return O}),t.d(e,"sendBridgeMessage",function(){return b}),t.d(e,"hasBridge",function(){return I}),t.d(e,"openBridge",function(){return P}),t.d(e,"linkWindow",function(){return R}),t.d(e,"linkUrl",function(){return A}),t.d(e,"destroyBridges",function(){return N})},function(n,e,t){"use strict";t.d({},"WeakMap",function(){return u});var r=t(0);function o(n,e){for(var t=0;t<n.length;t++)try{if(n[t]===e)return t}catch(n){}return-1}var i=Object.defineProperty,a=Date.now()%1e9,u=function(){function n(){if(function(e,t){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this),a+=1,this.name="__weakmap_"+(1e9*Math.random()>>>0)+"__"+a,function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var n=new WeakMap,e={};return Object.freeze(e),n.set(e,"__testvalue__"),"__testvalue__"===n.get(e)}catch(n){return!1}}())try{this.weakmap=new WeakMap}catch(n){}this.keys=[],this.values=[]}return n.prototype._cleanupClosedWindows=function(){for(var n=this.weakmap,e=this.keys,t=0;t<e.length;t++){var o=e[t];if(Object(r.isWindow)(o)&&Object(r.isWindowClosed)(o)){if(n)try{n.delete(o)}catch(n){}e.splice(t,1),this.values.splice(t,1),t-=1}}},n.prototype.isSafeToReadWrite=function(n){if(Object(r.isWindow)(n))return!1;try{n&&n.self,n&&n[this.name]}catch(n){return!1}return!0},n.prototype.set=function(n,e){if(!n)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{t.set(n,e)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var r=this.name,a=n[r];a&&a[0]===n?a[1]=e:i(n,r,{value:[n,e],writable:!0})}else{this._cleanupClosedWindows();var u=this.keys,c=this.values,s=o(u,n);-1===s?(u.push(n),c.push(e)):c[s]=e}},n.prototype.get=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{if(e.has(n))return e.get(n)}catch(n){delete this.weakmap}if(!this.isSafeToReadWrite(n)){this._cleanupClosedWindows();var t=o(this.keys,n);if(-1===t)return;return this.values[t]}var r=n[this.name];if(r&&r[0]===n)return r[1]},n.prototype.delete=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{e.delete(n)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var t=n[this.name];t&&t[0]===n&&(t[0]=t[1]=void 0)}else{this._cleanupClosedWindows();var r=this.keys,i=o(r,n);-1!==i&&(r.splice(i,1),this.values.splice(i,1))}},n.prototype.has=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{if(e.has(n))return!0}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var t=n[this.name];return!(!t||t[0]!==n)}return this._cleanupClosedWindows(),-1!==o(this.keys,n)},n.prototype.getOrSet=function(n,e){if(this.has(n))return this.get(n);var t=e();return this.set(n,t),t},n}();t.d(e,"a",function(){return u})},function(n,e,t){"use strict";t.d(e,"a",function(){return r}),t.d(e,"b",function(){return o}),t.d(e,"c",function(){return i});var r={MOCK:"mock:",FILE:"file:",ABOUT:"about:"},o="*",i={IFRAME:"iframe",POPUP:"popup"}},function(n,e,t){"use strict";e.a=function(){return!!(window.navigator.mockUserAgent||window.navigator.userAgent).match(/Android|webOS|iPhone|iPad|iPod|bada|Symbian|Palm|CriOS|BlackBerry|IEMobile|WindowsMobile|Opera Mini/i)}},function(n,e,t){"use strict";t(2),t(0),t(8);var r=t(6);t(10),e.b=function n(){return Object(r.e)(n,function(){try{if("undefined"==typeof window)return!1;if(window.localStorage){var n=Math.random().toString();window.localStorage.setItem("__test__localStorage__",n);var e=window.localStorage.getItem("__test__localStorage__");if(window.localStorage.removeItem("__test__localStorage__"),n===e)return!0}}catch(n){}return!1})},e.a=function(n,e,t){return n.addEventListener(e,t),{cancel:function(){n.removeEventListener(e,t)}}},"function"==typeof Symbol&&Symbol.iterator,Object.assign,Object.create(Error.prototype)},function(n,e,t){"use strict";e.a=function n(e){var t=e.name,i=e.version,a=void 0===i?"latest":i,u=e.lifetime,c=void 0===u?3e5:u;return Object(r.e)(n,function(){var n="__"+t+"_"+a+"_storage__",e=void 0;function i(t){var i=Object(o.b)(),a=void 0;if(e&&(a=e),!a&&i){var u=window.localStorage.getItem(n);u&&(a=JSON.parse(u))}a||(a=Object(r.c)()[n]),a||(a={id:Object(r.q)()}),a.id||(a.id=Object(r.q)()),e=a;var c=t(a);return i?window.localStorage.setItem(n,JSON.stringify(a)):Object(r.c)()[n]=a,e=null,c}function u(n){return i(function(e){var t=e.__session__,o=Date.now();return t&&o-t.created>c&&(t=null),t||(t={guid:Object(r.q)(),created:o}),e.__session__=t,n(t)})}return{getState:i,getID:function(){return i(function(n){return n.id})},getSessionState:function(n){return u(function(e){return e.state=e.state||{},n(e.state)})},getSessionID:function(){return u(function(n){return n.guid})}}},[{name:t,version:a,lifetime:c}])};var r=t(6),o=t(11)},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r={};t.d(r,"markWindowKnown",function(){return i.e}),t.d(r,"serializeMessage",function(){return R}),t.d(r,"deserializeMessage",function(){return A}),t.d(r,"ProxyWindow",function(){return _}),t.d(r,"cleanUpWindow",function(){return hn}),t.d(r,"Promise",function(){return y.a}),t.d(r,"bridge",function(){return mn}),t.d(r,"parent",function(){return wn}),t.d(r,"send",function(){return rn}),t.d(r,"requestPromises",function(){return en}),t.d(r,"request",function(){return tn}),t.d(r,"sendToParent",function(){return on}),t.d(r,"client",function(){return an}),t.d(r,"on",function(){return sn}),t.d(r,"listen",function(){return cn}),t.d(r,"once",function(){return fn}),t.d(r,"listener",function(){return dn}),t.d(r,"CONFIG",function(){return c.b}),t.d(r,"disable",function(){return ln});var o,i=t(5),a=t(0),u=t(3),c=t(1),s={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"},f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function d(n){return"object"===(void 0===n?"undefined":f(n))&&null!==n&&"string"==typeof n.__type__}function l(n){return void 0===n?s.UNDEFINED:null===n?s.NULL:Array.isArray(n)?s.ARRAY:"function"==typeof n?s.FUNCTION:"object"===(void 0===n?"undefined":f(n))?n instanceof Error?s.ERROR:"function"==typeof n.then?s.PROMISE:"[object RegExp]"===Object.prototype.toString.call(n)?s.REGEX:"[object Date]"===Object.prototype.toString.call(n)?s.DATE:s.OBJECT:"string"==typeof n?s.STRING:"number"==typeof n?s.NUMBER:"boolean"==typeof n?s.BOOLEAN:void 0}function w(n,e){return{__type__:n,__val__:e}}var h,m=((o={})[s.FUNCTION]=function(){},o[s.ERROR]=function(n){var e=n.message,t=n.stack,r=n.code;return w(s.ERROR,{message:e,stack:t,code:r})},o[s.PROMISE]=function(){},o[s.REGEX]=function(n){return w(s.REGEX,n.source)},o[s.DATE]=function(n){return w(s.DATE,n.toJSON())},o[s.ARRAY]=function(n){return n},o[s.OBJECT]=function(n){return n},o[s.STRING]=function(n){return n},o[s.NUMBER]=function(n){return n},o[s.BOOLEAN]=function(n){return n},o[s.NULL]=function(n){return n},o),p={},g=((h={})[s.FUNCTION]=function(){throw new Error("Function serialization is not implemented; nothing to deserialize")},h[s.ERROR]=function(n){var e=n.message,t=n.stack,r=n.code,o=new Error(e);return o.code=r,o.stack=t+"\n\n"+o.stack,o},h[s.PROMISE]=function(){throw new Error("Promise serialization is not implemented; nothing to deserialize")},h[s.REGEX]=function(n){return new RegExp(n)},h[s.DATE]=function(n){return new Date(n)},h[s.ARRAY]=function(n){return n},h[s.OBJECT]=function(n){return n},h[s.STRING]=function(n){return n},h[s.NUMBER]=function(n){return n},h[s.BOOLEAN]=function(n){return n},h[s.NULL]=function(n){return n},h),v={},y=t(2),O=t(4),b=Object(O.c)("winToProxyWindow"),E=Object(O.b)("idToProxyWindow");function j(){for(var n=0,e=E.keys(),t=null==e?0:e.length;n<t;n++){var r=e[n];E.get(r).shouldClean()&&E.del(r)}}var _=function(){function n(e,t){!function(e,t){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this),this.isProxyWindow=!0,this.serializedWindow=e,this.actualWindowPromise=new y.a,t&&this.setWindow(t),this.serializedWindow.getInstanceID=Object(u.memoizePromise)(this.serializedWindow.getInstanceID)}return n.prototype.getType=function(){return this.serializedWindow.type},n.prototype.isPopup=function(){return this.getType()===a.WINDOW_TYPE.POPUP},n.prototype.isIframe=function(){return this.getType()===a.WINDOW_TYPE.IFRAME},n.prototype.setLocation=function(n){var e=this;return y.a.try(function(){if(!e.actualWindow)return e.serializedWindow.setLocation(n);e.actualWindow.location=n}).then(function(){return e})},n.prototype.setName=function(n){var e=this;return y.a.try(function(){if(!e.actualWindow)return e.serializedWindow.setName(n);if(!Object(a.isSameDomain)(e.actualWindow))throw new Error("Can not set name for window on different domain");e.actualWindow.name=n,e.actualWindow.frameElement&&e.actualWindow.frameElement.setAttribute("name",n),(0,t(7).linkWindow)({win:e.actualWindow,name:n})}).then(function(){return e})},n.prototype.close=function(){var n=this;return y.a.try(function(){if(!n.actualWindow)return n.serializedWindow.close();n.actualWindow.close()}).then(function(){return n})},n.prototype.focus=function(){var n=this;return y.a.try(function(){return n.actualWindow&&n.actualWindow.focus(),n.serializedWindow.focus()}).then(function(){return n})},n.prototype.isClosed=function(){var n=this;return y.a.try(function(){return n.actualWindow?Object(a.isWindowClosed)(n.actualWindow):n.serializedWindow.isClosed()})},n.prototype.getWindow=function(){return this.actualWindow},n.prototype.setWindow=function(n){this.actualWindow=n,this.actualWindowPromise.resolve(n)},n.prototype.awaitWindow=function(){return this.actualWindowPromise},n.prototype.matchWindow=function(n){var e=this;return y.a.try(function(){return e.actualWindow?n===e.actualWindow:y.a.all([e.getInstanceID(),Object(i.b)(n)]).then(function(t){var r=t[0]===t[1];return r&&e.setWindow(n),r})})},n.prototype.unwrap=function(){return this.actualWindow||this},n.prototype.getInstanceID=function(){return this.actualWindow?Object(i.b)(this.actualWindow):this.serializedWindow.getInstanceID()},n.prototype.serialize=function(){return this.serializedWindow},n.prototype.shouldClean=function(){return this.actualWindow&&Object(a.isWindowClosed)(this.actualWindow)},n.unwrap=function(e){return n.isProxyWindow(e)?e.unwrap():e},n.serialize=function(e){return j(),n.toProxyWindow(e).serialize()},n.deserialize=function(e){return j(),E.getOrSet(e.id,function(){return new n(e)})},n.isProxyWindow=function(n){return Boolean(n&&!Object(a.isWindow)(n)&&n.isProxyWindow)},n.toProxyWindow=function(e){return j(),n.isProxyWindow(e)?e:b.getOrSet(e,function(){var r=Object(u.uniqueID)();return E.set(r,new n({id:r,type:Object(a.getOpener)(e)?a.WINDOW_TYPE.POPUP:a.WINDOW_TYPE.IFRAME,getInstanceID:function(){return Object(i.b)(e)},close:function(){return y.a.try(function(){e.close()})},focus:function(){return y.a.try(function(){e.focus()})},isClosed:function(){return y.a.try(function(){return Object(a.isWindowClosed)(e)})},setLocation:function(n){return y.a.try(function(){if(Object(a.isSameDomain)(e))try{if(e.location&&"function"==typeof e.location.replace)return void e.location.replace(n)}catch(n){}e.location=n})},setName:function(n){return y.a.try(function(){(0,t(7).linkWindow)({win:e,name:n}),e.name=n})}},e))})},n}(),S=Object(O.c)("methodStore"),W=Object(O.b)("proxyWindowMethods");function D(n,e,t,r,o){_.isProxyWindow(r)?W.set(n,{val:e,name:t,domain:o,source:r}):(W.del(n),S.getOrSet(r,function(){return{}})[n]={domain:o,name:t,val:e,source:r})}function T(n,e){return S.getOrSet(n,function(){return{}})[e]||W.get(e)}O.a.listeningForFunctions=O.a.listeningForFunctions||!1;var I=Object(u.once)(function(){O.a.listeningForFunctions||(O.a.listeningForFunctions=!0,O.a.on(c.d.METHOD,{origin:c.i},function(n){var e=n.source,t=n.origin,r=n.data,o=r.id,i=r.name;return y.a.try(function(){var n=T(e,o);if(!n)throw new Error("Could not find method '"+r.name+"' with id: "+r.id+" in "+Object(a.getDomain)(window));var c=n.source,s=n.domain,f=n.val;return y.a.try(function(){if(!Object(a.matchDomain)(s,t))throw new Error("Method '"+r.name+"' domain "+JSON.stringify(Object(u.isRegex)(n.domain)?n.domain.source:n.domain)+" does not match origin "+t+" in "+Object(a.getDomain)(window));if(_.isProxyWindow(c))return c.matchWindow(e).then(function(n){if(!n)throw new Error("Method call '"+r.name+"' failed - proxy window does not match source in "+Object(a.getDomain)(window))})}).then(function(){return f.apply({source:e,origin:t},r.args)},function(n){return y.a.try(function(){if(f.onError)return f.onError(n)}).then(function(){throw n})}).then(function(n){return{result:n,id:o,name:i}})})}))});function P(n,e,t,r){I();var o=t.__id__||Object(u.uniqueID)();n=_.unwrap(n);var i=t.__name__||t.name||r;return _.isProxyWindow(n)?(D(o,t,i,n,e),n.awaitWindow().then(function(n){D(o,t,i,n,e)})):D(o,t,i,n,e),w(c.h.CROSS_DOMAIN_FUNCTION,{id:o,name:i})}function R(n,e,t){var r;return function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p,t=JSON.stringify(n,function(n){var t=this[n];if(d(this))return t;var r=l(t);if(!r)return t;var o=e[r]||m[r];return o?o(t,n):t});return void 0===t?s.UNDEFINED:t}(t,((r={})[s.PROMISE]=function(t,r){return function(n,e,t,r){return w(c.h.CROSS_DOMAIN_ZALGO_PROMISE,{then:P(n,e,function(n,e){return t.then(n,e)},r)})}(n,e,t,r)},r[s.FUNCTION]=function(t,r){return P(n,e,t,r)},r[s.OBJECT]=function(n){return Object(a.isWindow)(n)||_.isProxyWindow(n)?(e=n,w(c.h.CROSS_DOMAIN_WINDOW,_.serialize(e))):n;var e},r))}function A(n,e,t){var r;return function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v;if(n!==s.UNDEFINED)return JSON.parse(n,function(n,t){if(d(this))return t;var r=void 0,o=void 0;if(d(t)?(r=t.__type__,o=t.__val__):(r=l(t),o=t),!r)return o;var i=e[r]||g[r];return i?i(o,n):o})}(t,((r={})[c.h.CROSS_DOMAIN_ZALGO_PROMISE]=function(n){return e=n.then,new y.a(e);var e},r[c.h.CROSS_DOMAIN_FUNCTION]=function(t){return function(n,e,t){var r=t.id,o=t.name,i=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};function i(){var u=arguments;return _.toProxyWindow(n).awaitWindow().then(function(n){var s=T(n,r);return s&&s.val!==i?s.val.apply({source:window,origin:Object(a.getDomain)()},u):O.a.send(n,c.d.METHOD,{id:r,name:o,args:Array.prototype.slice.call(u)},{domain:e,fireAndForget:t.fireAndForget}).then(function(n){if(!t.fireAndForget)return n.data.result})}).catch(function(n){throw n})}return i.__name__=o,i.__origin__=e,i.__source__=n,i.__id__=r,i.origin=e,i},u=i();return u.fireAndForget=i({fireAndForget:!0}),u}(n,e,t)},r[c.h.CROSS_DOMAIN_WINDOW]=function(n){return e=n,_.deserialize(e);var e},r))}var M={};M[c.g.POST_MESSAGE]=function(n,e,t){(Array.isArray(t)?t:"string"==typeof t?[t]:[c.i]).map(function(e){if(0===e.indexOf(c.f.MOCK)){if(window.location.protocol===c.f.FILE)return c.i;if(!Object(a.isActuallySameDomain)(n))throw new Error("Attempting to send messsage to mock domain "+e+", but window is actually cross-domain");return Object(a.getActualDomain)(n)}return 0===e.indexOf(c.f.FILE)?c.i:e}).forEach(function(t){return n.postMessage(e,t)})};var N=t(7),C=N.sendBridgeMessage,x=N.needsBridgeForBrowser,k=N.isBridge;M[c.g.BRIDGE]=function(n,e,t){if(x()||k()){if(Object(a.isSameDomain)(n))throw new Error("Post message through bridge disabled between same domain windows");if(!1!==Object(a.isSameTopWindow)(window,n))throw new Error("Can only use bridge to communicate between two different windows, not between frames");return C(n,t,e)}},M[c.g.GLOBAL]=function(n,e){if(Object(i.f)()){if(!Object(a.isSameDomain)(n))throw new Error("Post message through global disabled between different domain windows");if(!1!==Object(a.isSameTopWindow)(window,n))throw new Error("Can only use global to communicate between two different windows, not between frames");var t=n[c.j.POSTROBOT];if(!t)throw new Error("Can not find postRobot global on foreign window");return t.receiveMessage({source:window,origin:Object(a.getDomain)(),data:e})}};var B=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n};function U(n,e,t){return y.a.try(function(){var r;if(Object(a.isWindowClosed)(n))throw new Error("Window is closed");var o=R(n,e,((r={})[c.j.POSTROBOT]=B({id:Object(u.uniqueID)()},t),r)),i=[];return y.a.map(Object.keys(M),function(t){return y.a.try(function(){if(!c.b.ALLOWED_POST_MESSAGE_METHODS[t])throw new Error("Strategy disallowed: "+t);return M[t](n,o,e)}).then(function(){return i.push(t+": success"),!0},function(n){return i.push(t+": "+Object(u.stringifyError)(n)+"\n"),!1})}).then(function(n){var e=n.some(Boolean),r=t.type+" "+t.name+" "+(e?"success":"error")+":\n - "+i.join("\n - ")+"\n";if(!e)throw new Error(r)})})}var F=Object(O.b)("responseListeners"),L=Object(O.c)("requestListeners"),z=Object(O.b)("erroredResponseListeners");O.a.WINDOW_WILDCARD=O.a.WINDOW_WILDCARD||new function(){};var q,H="__domain_regex__";function G(n){return F.get(n)}function K(n){F.del(n)}function J(n){return z.has(n)}function Y(n){var e=n.name,t=n.win,r=n.domain;if(t===c.i&&(t=null),r===c.i&&(r=null),!e)throw new Error("Name required to get request listener");for(var o=0,i=[t,O.a.WINDOW_WILDCARD],u=null==i?0:i.length;o<u;o++){var s=i[o];if(s){var f=L.get(s);if(f){var d=f[e];if(d){if(r&&"string"==typeof r){if(d[r])return d[r];if(d[H])for(var l=0,w=d[H],h=null==w?0:w.length;l<h;l++){var m=w[l],p=m.regex,g=m.listener;if(Object(a.matchDomain)(p,r))return g}}if(d[c.i])return d[c.i]}}}}}var Q=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},X=((q={})[c.e.REQUEST]=function(n,e,t){var r=Y({name:t.name,win:n,domain:e});function o(r,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t.fireAndForget||Object(a.isWindowClosed)(n)?y.a.resolve():U(n,e,Q({type:r,ack:o,hash:t.hash,name:t.name},i))}return t.name===c.d.METHOD&&t.data&&"string"==typeof t.data.name?t.data.name:t.name,y.a.all([o(c.e.ACK),y.a.try(function(){if(!r)throw new Error("No handler found for post message: "+t.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!Object(a.matchDomain)(r.domain,e))throw new Error("Request origin "+e+" does not match domain "+r.domain.toString());var o=t.data;return r.handler({source:n,origin:e,data:o})}).then(function(n){return o(c.e.RESPONSE,c.c.SUCCESS,{data:n})},function(n){return o(c.e.RESPONSE,c.c.ERROR,{error:n})})]).then(u.noop).catch(function(n){if(r&&r.handleError)return r.handleError(n);throw n})},q[c.e.ACK]=function(n,e,t){if(!J(t.hash)){var r=G(t.hash);if(!r)throw new Error("No handler found for post message ack for message: "+t.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!Object(a.matchDomain)(r.domain,e))throw new Error("Ack origin "+e+" does not match domain "+r.domain.toString());r.ack=!0}},q[c.e.RESPONSE]=function(n,e,t){if(!J(t.hash)){var r=G(t.hash);if(!r)throw new Error("No handler found for post message response for message: "+t.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!Object(a.matchDomain)(r.domain,e))throw new Error("Response origin "+e+" does not match domain "+Object(a.stringifyDomainPattern)(r.domain));if(K(t.hash),t.ack===c.c.ERROR)return r.respond(t.error,null);if(t.ack===c.c.SUCCESS){var o=t.data;return r.respond(null,{source:n,origin:e,data:o})}}},q),Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},V=Object(O.b)("receivedMessages");function $(n){if(!window||window.closed)throw new Error("Message recieved in closed window");try{if(!n.source)return}catch(n){return}var e=n.source,t=n.origin,r=function(n,e,t){var r=void 0;try{r=A(e,t,n)}catch(n){return}if(r&&"object"===(void 0===r?"undefined":Z(r))&&null!==r&&(r=r[c.j.POSTROBOT])&&"object"===(void 0===r?"undefined":Z(r))&&null!==r&&r.type&&"string"==typeof r.type&&X[r.type])return r}(n.data,e,t);r&&(Object(i.e)(e),V.has(r.id)||(V.set(r.id,!0),Object(a.isWindowClosed)(e)&&!r.fireAndForget||X[r.type](e,t,r)))}function nn(n){try{Object(u.noop)(n.source)}catch(n){return}var e={source:n.source||n.sourceElement,origin:n.origin||n.originalEvent&&n.originalEvent.origin,data:n.data};if(e.source){if(!e.origin)throw new Error("Post message did not have origin domain");$(e)}}O.a.receiveMessage=$;var en=Object(O.c)("requestPromises");function tn(n){return y.a.try(function(){if(!n.name)throw new Error("Expected options.name");var e=n.name,t=void 0,r=void 0;if("string"==typeof n.window){var o=document.getElementById(n.window);if(!o)throw new Error("Expected options.window "+Object.prototype.toString.call(n.window)+" to be a valid element id");if("iframe"!==o.tagName.toLowerCase())throw new Error("Expected options.window "+Object.prototype.toString.call(n.window)+" to be an iframe");if(!o.contentWindow)throw new Error("Iframe must have contentWindow. Make sure it has a src attribute and is in the DOM.");t=o.contentWindow}else if(n.window instanceof HTMLIFrameElement){if("iframe"!==n.window.tagName.toLowerCase())throw new Error("Expected options.window "+Object.prototype.toString.call(n.window)+" to be an iframe");if(n.window&&!n.window.contentWindow)throw new Error("Iframe must have contentWindow. Make sure it has a src attribute and is in the DOM.");n.window&&n.window.contentWindow&&(t=n.window.contentWindow)}else t=n.window;if(!t)throw new Error("Expected options.window to be a window object, iframe, or iframe element id.");var s=t;r=n.domain||c.i;var f=n.name+"_"+Object(u.uniqueID)();if(Object(a.isWindowClosed)(s))throw new Error("Target window is closed");var d=!1,l=en.getOrSet(s,function(){return[]}),w=y.a.try(function(){if(Object(a.isAncestor)(window,s))return Object(i.a)(s,n.timeout||c.b.CHILD_WINDOW_TIMEOUT)}).then(function(){var n=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).domain;if(Object(u.isRegex)(r)&&!n)return Object(i.g)(s)}).then(function(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).domain;if(Object(u.isRegex)(r)){if(!Object(a.matchDomain)(r,t))throw new Error("Remote window domain "+t+" does not match regex: "+r.toString());r=t}if("string"!=typeof r&&!Array.isArray(r))throw new TypeError("Expected domain to be a string or array");var o=r;return e===c.d.METHOD&&n.data&&"string"==typeof n.data.name&&n.data.name,new y.a(function(t,r){var u=void 0;if(n.fireAndForget||function(n,e){F.set(n,e)}(f,u={name:e,window:s,domain:o,respond:function(n,e){n||(d=!0,l.splice(l.indexOf(w,1))),n?r(n):t(e)}}),U(s,o,{type:c.e.REQUEST,hash:f,name:e,data:n.data,fireAndForget:Boolean(n.fireAndForget)}).catch(r),n.fireAndForget)return t();var h=Object(i.d)(s)?c.b.ACK_TIMEOUT_KNOWN:c.b.ACK_TIMEOUT,m=n.timeout||c.b.RES_TIMEOUT,p=h,g=m,v=100;setTimeout(function n(){if(!d){if(Object(a.isWindowClosed)(s))return u.ack?r(new Error("Window closed for "+e+" before response")):r(new Error("Window closed for "+e+" before ack"));if(p=Math.max(p-v,0),-1!==g&&(g=Math.max(g-v,0)),u.ack){if(-1===g)return;v=Math.min(g,2e3)}else{if(0===p)return r(new Error("No ack for postMessage "+e+" in "+Object(a.getDomain)()+" in "+h+"ms"));if(0===g)return r(new Error("No response for postMessage "+e+" in "+Object(a.getDomain)()+" in "+m+"ms"))}setTimeout(n,v)}},v)})});return w.catch(function(){!function(n){z.set(n,!0)}(f),K(f)}),l.push(w),w})}function rn(n,e,t,r){return(r=r||{}).window=n,r.name=e,r.data=t,tn(r)}function on(n,e,t){var r=Object(a.getAncestor)();return r?rn(r,n,e,t):new y.a(function(n,e){return e(new Error("Window does not have a parent"))})}function an(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!n.window)throw new Error("Expected options.window");var e=n.window;return{send:function(t,r){return rn(e,t,r,n)}}}O.a.send=rn;var un="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function cn(n){if(!n.name)throw new Error("Expected options.name");if(!n.handler)throw new Error("Expected options.handler");var e=n.name,t=n.window,r=n.domain,o={handler:n.handler,handleError:n.errorHandler||function(n){throw n},window:t,domain:r||c.i,name:e},i=function n(e,t){var r=e.name,o=e.win,i=e.domain;if(!r||"string"!=typeof r)throw new Error("Name required to add request listener");if(Array.isArray(o)){for(var a=[],s=0,f=o,d=null==f?0:f.length;s<d;s++){var l=f[s];a.push(n({name:r,domain:i,win:l},t))}return{cancel:function(){for(var n=0,e=null==a?0:a.length;n<e;n++)a[n].cancel()}}}if(Array.isArray(i)){for(var w=[],h=0,m=i,p=null==m?0:m.length;h<p;h++){var g=m[h];w.push(n({name:r,win:o,domain:g},t))}return{cancel:function(){for(var n=0,e=null==w?0:w.length;n<e;n++)w[n].cancel()}}}var v=Y({name:r,win:o,domain:i});if(o&&o!==c.i||(o=O.a.WINDOW_WILDCARD),i=i||c.i,v)throw o&&i?new Error("Request listener already exists for "+r+" on domain "+i.toString()+" for "+(o===O.a.WINDOW_WILDCARD?"wildcard":"specified")+" window"):o?new Error("Request listener already exists for "+r+" for "+(o===O.a.WINDOW_WILDCARD?"wildcard":"specified")+" window"):i?new Error("Request listener already exists for "+r+" on domain "+i.toString()):new Error("Request listener already exists for "+r);var y=L.getOrSet(o,function(){return{}}),b=Object(u.getOrSet)(y,r,function(){return{}}),E=i.toString(),j=void 0,_=void 0;return Object(u.isRegex)(i)?(j=Object(u.getOrSet)(b,H,function(){return[]}),_={regex:i,listener:t},j.push(_)):b[E]=t,{cancel:function(){delete b[E],_&&(j.splice(j.indexOf(_,1)),j.length||delete b[H]),Object.keys(b).length||delete y[r],o&&!Object.keys(y).length&&L.del(o)}}}({name:e,win:t,domain:r},o);if(n.once){var s=o.handler;o.handler=Object(u.once)(function(){return i.cancel(),s.apply(this,arguments)})}if(o.window&&n.errorOnClose)var f=Object(u.safeInterval)(function(){t&&"object"===(void 0===t?"undefined":un(t))&&Object(a.isWindowClosed)(t)&&(f.cancel(),o.handleError(new Error("Post message target window is closed")))},50);return{cancel:function(){i.cancel()}}}function sn(n,e,t){return"function"==typeof e&&(t=e,e={}),(e=e||{}).name=n,e.handler=t||e.handler,cn(e)}function fn(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments[2];"function"==typeof e&&(t=e,e={}),e=e||{},t=t||e.handler;var r=e.errorHandler,o=new y.a(function(o,i){(e=e||{}).name=n,e.once=!0,e.handler=function(n){if(o(n),t)return t(n)},e.errorHandler=function(n){if(i(n),r)return r(n)}}),i=cn(e);return o.cancel=i.cancel,o}function dn(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{on:function(e,t){return sn(e,n,t)}}}function ln(){delete window[c.j.POSTROBOT],window.removeEventListener("message",nn)}O.a.on=sn;var wn=Object(a.getAncestor)();function hn(n){for(var e=0,t=en.get(n,[]),r=null==t?0:t.length;e<r;e++)t[e].reject(new Error("Window cleaned up before response")).catch(u.noop)}var mn=t(23);O.a.initialized||(O.a.initialized=!0,Object(u.addEventListener)(window,"message",nn),mn&&mn.openTunnelToOpener(),Object(i.c)()),t.d(e,"markWindowKnown",function(){return i.e}),t.d(e,"serializeMessage",function(){return R}),t.d(e,"deserializeMessage",function(){return A}),t.d(e,"ProxyWindow",function(){return _}),t.d(e,"cleanUpWindow",function(){return hn}),t.d(e,"Promise",function(){return y.a}),t.d(e,"bridge",function(){return mn}),t.d(e,"parent",function(){return wn}),t.d(e,"send",function(){return rn}),t.d(e,"requestPromises",function(){return en}),t.d(e,"request",function(){return tn}),t.d(e,"sendToParent",function(){return on}),t.d(e,"client",function(){return an}),t.d(e,"on",function(){return sn}),t.d(e,"listen",function(){return cn}),t.d(e,"once",function(){return fn}),t.d(e,"listener",function(){return dn}),t.d(e,"CONFIG",function(){return c.b}),t.d(e,"disable",function(){return ln}),e.default=r},function(n,e,t){"use strict";function r(n){return"[object RegExp]"===Object.prototype.toString.call(n)}var o=t(9);e.g=u,e.f=c,e.a=f,e.c=d,e.i=l,e.l=w,e.o=function(n){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];try{if(n===window)return!1}catch(n){return!0}try{if(!n)return!0}catch(n){return!0}try{if(n.closed)return!0}catch(n){return!n||n.message!==i}if(e&&w(n))try{if(n.mockclosed)return!0}catch(n){}try{if(!n.parent||!n.top)return!0}catch(n){}var t=function(n,e){for(var t=0;t<n.length;t++)try{if(n[t]===e)return t}catch(n){}return-1}(y,n);if(-1!==t){var r=O[t];if(r&&function(n){if(!n.contentWindow)return!0;if(!n.parentNode)return!0;var e=n.ownerDocument;return!(!e||!e.documentElement||e.documentElement.contains(n))}(r))return!0}return!1},e.p=function(n){if(function(){for(var n=0;n<y.length;n++){var e=!1;try{e=y[n].closed}catch(n){}e&&(O.splice(n,1),y.splice(n,1))}}(),n&&n.contentWindow)try{y.push(n.contentWindow),O.push(n)}catch(n){}},e.h=function(n){return(n=n||window).navigator.mockUserAgent||n.navigator.userAgent},e.e=function(n,e){for(var t=m(n),r=0,o=null==t?0:t.length;r<o;r++){var i=t[r];try{if(w(i)&&i.name===e&&-1!==t.indexOf(i))return i}catch(n){}}try{if(-1!==t.indexOf(n.frames[e]))return n.frames[e]}catch(n){}try{if(-1!==t.indexOf(n[e]))return n[e]}catch(n){}},e.k=function(n,e){return n===c(e)},e.b=b,e.j=function(n,e){var t=b(e);if(t)return t===n;if(e===n)return!1;if(g(e)===e)return!1;for(var r=0,o=m(n),i=null==o?0:o.length;r<i;r++)if(o[r]===e)return!0;return!1},e.m=function(n,e){var t=g(n)||n,r=g(e)||e;try{if(t&&r)return t===r}catch(n){}var o=v(n),i=v(e);if(E(o,i))return!0;var a=c(t),u=c(r);return!(a&&E(v(a),i)||(u&&E(v(u),o),1))},e.q=function n(e,t){if("string"==typeof e){if("string"==typeof t)return e===o.b||t===e;if(r(t))return!1;if(Array.isArray(t))return!1}return r(e)?r(t)?e.toString()===t.toString():!Array.isArray(t)&&Boolean(t.match(e)):!!Array.isArray(e)&&(Array.isArray(t)?JSON.stringify(e)===JSON.stringify(t):!r(t)&&e.some(function(e){return n(e,t)}))},e.s=function(n){return Array.isArray(n)?"("+n.join(" | ")+")":r(n)?"RegExp("+n.toString():n.toString()},e.d=j,e.n=function(n){try{if(n===window)return!0}catch(n){if(n&&n.message===i)return!0}try{if("[object Window]"===Object.prototype.toString.call(n))return!0}catch(n){if(n&&n.message===i)return!0}try{if(window.Window&&n instanceof window.Window)return!0}catch(n){if(n&&n.message===i)return!0}try{if(n&&n.self===n)return!0}catch(n){if(n&&n.message===i)return!0}try{if(n&&n.parent===n)return!0}catch(n){if(n&&n.message===i)return!0}try{if(n&&n.top===n)return!0}catch(n){if(n&&n.message===i)return!0}try{n&&n.__cross_domain_utils_window_check__}catch(n){return!0}return!1},e.r=function(n){if(0!==j(n).indexOf(o.a.MOCK))return n;throw new Error("Mock urls not supported out of test mode")};var i="Call was rejected by callee.\r\n";function a(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).location.protocol===o.a.ABOUT}function u(n){if(n)try{if(n.parent&&n.parent!==n)return n.parent}catch(n){}}function c(n){if(n&&!u(n))try{return n.opener}catch(n){}}function s(n){try{return n&&n.location&&n.location.href,!0}catch(n){}return!1}function f(n){var e=(n=n||window).location;if(!e)throw new Error("Can not read window location");var t=e.protocol;if(!t)throw new Error("Can not read window protocol");if(t===o.a.FILE)return o.a.FILE+"//";if(t===o.a.ABOUT){var r=u(n);return r&&s(r)?f(r):o.a.ABOUT+"//"}var i=e.host;if(!i)throw new Error("Can not read window host");return t+"//"+i}function d(n){var e=f(n=n||window);return e&&n.mockDomain&&0===n.mockDomain.indexOf(o.a.MOCK)?n.mockDomain:e}function l(n){try{if(n===window)return!0}catch(n){}try{var e=Object.getOwnPropertyDescriptor(n,"location");if(e&&!1===e.enumerable)return!1}catch(n){}try{if(a(n)&&s(n))return!0}catch(n){}try{if(f(n)===f(window))return!0}catch(n){}return!1}function w(n){if(!l(n))return!1;try{if(n===window)return!0;if(a(n)&&s(n))return!0;if(d(window)===d(n))return!0}catch(n){}return!1}function h(n,e){if(!n||!e)return!1;var t=u(e);return t?t===n:-1!==function(n){var e=[];try{for(;n.parent!==n;)e.push(n.parent),n=n.parent}catch(n){}return e}(e).indexOf(n)}function m(n){var e=[],t=void 0;try{t=n.frames}catch(e){t=n}var r=void 0;try{r=t.length}catch(n){}if(0===r)return e;if(r){for(var o=0;o<r;o++){var i=void 0;try{i=t[o]}catch(n){continue}e.push(i)}return e}for(var a=0;a<100;a++){var u=void 0;try{u=t[a]}catch(n){return e}if(!u)return e;e.push(u)}return e}function p(n){for(var e=[],t=0,r=m(n),o=null==r?0:r.length;t<o;t++){var i=r[t];e.push(i);for(var a=0,u=p(i),c=null==u?0:u.length;a<c;a++){var s=u[a];e.push(s)}}return e}function g(n){if(n){try{if(n.top)return n.top}catch(n){}if(u(n)===n)return n;try{if(h(window,n)&&window.top)return window.top}catch(n){}try{if(h(n,window)&&window.top)return window.top}catch(n){}for(var e=0,t=p(n),r=null==t?0:t.length;e<r;e++){var o=t[e];try{if(o.top)return o.top}catch(n){}if(u(o)===o)return o}}}function v(n){var e=g(n);if(!e)throw new Error("Can not determine top window");return[].concat(p(e),[e])}var y=[],O=[];function b(n){return c(n=n||window)||u(n)||void 0}function E(n,e){for(var t=0,r=null==n?0:n.length;t<r;t++)for(var o=n[t],i=0,a=null==e?0:e.length;i<a;i++)if(o===e[i])return!0;return!1}function j(n){return n.match(/^(https?|mock|file):\/\//)?n.split("/").slice(0,3).join("/"):d()}},function(n,e){},function(n,e,t){"use strict";t(6),t(12)},function(n,e,t){"use strict";t(6)},function(n,e,t){"use strict";t(2),t(0)},function(n,e){},function(n,e,t){"use strict";t(6)},function(n,e,t){"use strict"},function(n,e,t){"use strict";t(2),t(6)},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=t(7);t.d(e,"openBridge",function(){return r.openBridge}),t.d(e,"linkWindow",function(){return r.linkWindow}),t.d(e,"linkUrl",function(){return r.linkUrl}),t.d(e,"isBridge",function(){return r.isBridge}),t.d(e,"needsBridge",function(){return r.needsBridge}),t.d(e,"needsBridgeForBrowser",function(){return r.needsBridgeForBrowser}),t.d(e,"hasBridge",function(){return r.hasBridge}),t.d(e,"needsBridgeForWin",function(){return r.needsBridgeForWin}),t.d(e,"needsBridgeForDomain",function(){return r.needsBridgeForDomain}),t.d(e,"openTunnelToOpener",function(){return r.openTunnelToOpener}),t.d(e,"destroyBridges",function(){return r.destroyBridges})}])}); | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("postRobot",[],e):"object"==typeof exports?exports.postRobot=e():n.postRobot=e()}("undefined"!=typeof self?self:this,function(){return function(n){var e={};function r(t){if(e[t])return e[t].exports;var o=e[t]={i:t,l:!1,exports:{}};return n[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=n,r.c=e,r.d=function(n,e,t){r.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:t})},r.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},r.t=function(n,e){if(1&e&&(n=r(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)r.d(t,o,function(e){return n[e]}.bind(null,o));return t},r.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(e,"a",e),e},r.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},r.p="",r(r.s=0)}([function(n,e,r){"use strict";r.r(e);var t={};function o(n){return"[object RegExp]"===Object.prototype.toString.call(n)}r.r(t),r.d(t,"WeakMap",function(){return K});var i={MOCK:"mock:",FILE:"file:",ABOUT:"about:"},a="*",u="Call was rejected by callee.\r\n";function s(n){return void 0===n&&(n=window),n.location.protocol===i.ABOUT}function c(n){if(n)try{if(n.parent&&n.parent!==n)return n.parent}catch(n){}}function f(n){if(n&&!c(n))try{return n.opener}catch(n){}}function d(n){try{return n&&n.location&&n.location.href,!0}catch(n){}return!1}function w(n){var e=(n=n||window).location;if(!e)throw new Error("Can not read window location");var r=e.protocol;if(!r)throw new Error("Can not read window protocol");if(r===i.FILE)return i.FILE+"//";if(r===i.ABOUT){var t=c(n);return t&&d(t)?w(t):i.ABOUT+"//"}var o=e.host;if(!o)throw new Error("Can not read window host");return r+"//"+o}function l(n){var e=w(n=n||window);return e&&n.mockDomain&&0===n.mockDomain.indexOf(i.MOCK)?n.mockDomain:e}function h(n){try{if(n===window)return!0}catch(n){}try{var e=Object.getOwnPropertyDescriptor(n,"location");if(e&&!1===e.enumerable)return!1}catch(n){}try{if(s(n)&&d(n))return!0}catch(n){}try{if(w(n)===w(window))return!0}catch(n){}return!1}function m(n){if(!h(n))return!1;try{if(n===window)return!0;if(s(n)&&d(n))return!0;if(l(window)===l(n))return!0}catch(n){}return!1}function v(n,e){if(!n||!e)return!1;var r=c(e);return r?r===n:-1!==function(n){var e=[];try{for(;n.parent!==n;)e.push(n.parent),n=n.parent}catch(n){}return e}(e).indexOf(n)}function p(n){var e,r,t=[];try{e=n.frames}catch(r){e=n}try{r=e.length}catch(n){}if(0===r)return t;if(r){for(var o=0;o<r;o++){var i=void 0;try{i=e[o]}catch(n){continue}t.push(i)}return t}for(var a=0;a<100;a++){var u=void 0;try{u=e[a]}catch(n){return t}if(!u)return t;t.push(u)}return t}function g(n){for(var e=[],r=0,t=p(n);r<t.length;r++){var o=t[r];e.push(o);for(var i=0,a=g(o);i<a.length;i++){var u=a[i];e.push(u)}}return e}function y(n){if(n){try{if(n.top)return n.top}catch(n){}if(c(n)===n)return n;try{if(v(window,n)&&window.top)return window.top}catch(n){}try{if(v(n,window)&&window.top)return window.top}catch(n){}for(var e=0,r=g(n);e<r.length;e++){var t=r[e];try{if(t.top)return t.top}catch(n){}if(c(t)===t)return t}}}function E(n){var e=y(n);if(!e)throw new Error("Can not determine top window");return[].concat(g(e),[e])}var _=[],O=[];function b(n,e){void 0===e&&(e=!0);try{if(n===window)return!1}catch(n){return!0}try{if(!n)return!0}catch(n){return!0}try{if(n.closed)return!0}catch(n){return!n||n.message!==u}if(e&&m(n))try{if(n.mockclosed)return!0}catch(n){}try{if(!n.parent||!n.top)return!0}catch(n){}var r=function(n,e){for(var r=0;r<n.length;r++)try{if(n[r]===e)return r}catch(n){}return-1}(_,n);if(-1!==r){var t=O[r];if(t&&function(n){if(!n.contentWindow)return!0;if(!n.parentNode)return!0;var e=n.ownerDocument;return!(!e||!e.documentElement||e.documentElement.contains(n))}(t))return!0}return!1}function W(n){return(n=n||window).navigator.mockUserAgent||n.navigator.userAgent}function S(n,e){for(var r=p(n),t=0;t<r.length;t++){var o=r[t];try{if(m(o)&&o.name===e&&-1!==r.indexOf(o))return o}catch(n){}}try{if(-1!==r.indexOf(n.frames[e]))return n.frames[e]}catch(n){}try{if(-1!==r.indexOf(n[e]))return n[e]}catch(n){}}function R(n,e){return n===f(e)}function A(n){return f(n=n||window)||c(n)||void 0}function N(n,e){for(var r=0;r<n.length;r++)for(var t=n[r],o=0;o<e.length;o++)if(t===e[o])return!0;return!1}function x(n,e){var r=y(n)||n,t=y(e)||e;try{if(r&&t)return r===t}catch(n){}var o=E(n),i=E(e);if(N(o,i))return!0;var a=f(r),u=f(t);return!(a&&N(E(a),i)||(u&&N(E(u),o),1))}function M(n,e){if("string"==typeof n){if("string"==typeof e)return n===a||e===n;if(o(e))return!1;if(Array.isArray(e))return!1}return o(n)?o(e)?n.toString()===e.toString():!Array.isArray(e)&&Boolean(e.match(n)):!!Array.isArray(n)&&(Array.isArray(e)?JSON.stringify(n)===JSON.stringify(e):!o(e)&&n.some(function(n){return M(n,e)}))}function j(n){return n.match(/^(https?|mock|file):\/\//)?n.split("/").slice(0,3).join("/"):l()}function P(n){try{if(n===window)return!0}catch(n){if(n&&n.message===u)return!0}try{if("[object Window]"===Object.prototype.toString.call(n))return!0}catch(n){if(n&&n.message===u)return!0}try{if(window.Window&&n instanceof window.Window)return!0}catch(n){if(n&&n.message===u)return!0}try{if(n&&n.self===n)return!0}catch(n){if(n&&n.message===u)return!0}try{if(n&&n.parent===n)return!0}catch(n){if(n&&n.message===u)return!0}try{if(n&&n.top===n)return!0}catch(n){if(n&&n.message===u)return!0}try{n&&n.__cross_domain_utils_window_check__}catch(n){return!0}return!1}function I(n){try{if(!n)return!1;if("undefined"!=typeof Promise&&n instanceof Promise)return!0;if("undefined"!=typeof window&&window.Window&&n instanceof window.Window)return!1;if("undefined"!=typeof window&&window.constructor&&n instanceof window.constructor)return!1;var e={}.toString;if(e){var r=e.call(n);if("[object Window]"===r||"[object global]"===r||"[object DOMWindow]"===r)return!1}if("function"==typeof n.then)return!0}catch(n){return!1}return!1}var k,T=[],D=[],C=0;function L(){if(!C&&k){var n=k;k=null,n.resolve()}}function B(){C+=1}function z(){C-=1,L()}var F=function(){function n(n){var e=this;if(this.resolved=void 0,this.rejected=void 0,this.errorHandled=void 0,this.value=void 0,this.error=void 0,this.handlers=void 0,this.dispatching=void 0,this.stack=void 0,this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],n){var r,t,o=!1,i=!1,a=!1;B();try{n(function(n){a?e.resolve(n):(o=!0,r=n)},function(n){a?e.reject(n):(i=!0,t=n)})}catch(n){return z(),void this.reject(n)}z(),a=!0,o?this.resolve(r):i&&this.reject(t)}}var e=n.prototype;return e.resolve=function(n){if(this.resolved||this.rejected)return this;if(I(n))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=n,this.dispatch(),this},e.reject=function(n){var e=this;if(this.resolved||this.rejected)return this;if(I(n))throw new Error("Can not reject promise with another promise");if(!n){var r=n&&"function"==typeof n.toString?n.toString():Object.prototype.toString.call(n);n=new Error("Expected reject to be called with Error, got "+r)}return this.rejected=!0,this.error=n,this.errorHandled||setTimeout(function(){e.errorHandled||function(n,e){if(-1===T.indexOf(n)){T.push(n),setTimeout(function(){throw n},1);for(var r=0;r<D.length;r++)D[r](n,e)}}(n,e)},1),this.dispatch(),this},e.asyncReject=function(n){return this.errorHandled=!0,this.reject(n),this},e.dispatch=function(){var e=this,r=this.dispatching,t=this.resolved,o=this.rejected,i=this.handlers;if(!r&&(t||o)){this.dispatching=!0,B();for(var a=function(r){var a=i[r],u=a.onSuccess,s=a.onError,c=a.promise,f=void 0;if(t)try{f=u?u(e.value):e.value}catch(n){return c.reject(n),"continue"}else if(o){if(!s)return c.reject(e.error),"continue";try{f=s(e.error)}catch(n){return c.reject(n),"continue"}}f instanceof n&&(f.resolved||f.rejected)?(f.resolved?c.resolve(f.value):c.reject(f.error),f.errorHandled=!0):I(f)?f instanceof n&&(f.resolved||f.rejected)?f.resolved?c.resolve(f.value):c.reject(f.error):f.then(function(n){c.resolve(n)},function(n){c.reject(n)}):c.resolve(f)},u=0;u<i.length;u++)a(u);i.length=0,this.dispatching=!1,z()}},e.then=function(e,r){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.then expected a function for success handler");if(r&&"function"!=typeof r&&!r.call)throw new Error("Promise.then expected a function for error handler");var t=new n;return this.handlers.push({promise:t,onSuccess:e,onError:r}),this.errorHandled=!0,this.dispatch(),t},e.catch=function(n){return this.then(void 0,n)},e.finally=function(e){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.finally expected a function");return this.then(function(r){return n.try(e).then(function(){return r})},function(r){return n.try(e).then(function(){throw r})})},e.timeout=function(n,e){var r=this;if(this.resolved||this.rejected)return this;var t=setTimeout(function(){r.resolved||r.rejected||r.reject(e||new Error("Promise timed out after "+n+"ms"))},n);return this.then(function(n){return clearTimeout(t),n})},e.toPromise=function(){if("undefined"==typeof Promise)throw new TypeError("Could not find Promise");return Promise.resolve(this)},n.resolve=function(e){return e instanceof n?e:I(e)?new n(function(n,r){return e.then(n,r)}):(new n).resolve(e)},n.reject=function(e){return(new n).reject(e)},n.asyncReject=function(e){return(new n).asyncReject(e)},n.all=function(e){var r=new n,t=e.length,o=[];if(!t)return r.resolve(o),r;for(var i=function(i){var a=e[i];if(a instanceof n){if(a.resolved)return o[i]=a.value,t-=1,"continue"}else if(!I(a))return o[i]=a,t-=1,"continue";n.resolve(a).then(function(n){o[i]=n,0==(t-=1)&&r.resolve(o)},function(n){r.reject(n)})},a=0;a<e.length;a++)i(a);return 0===t&&r.resolve(o),r},n.hash=function(e){var r={};return n.all(Object.keys(e).map(function(t){return n.resolve(e[t]).then(function(n){r[t]=n})})).then(function(){return r})},n.map=function(e,r){return n.all(e.map(r))},n.onPossiblyUnhandledException=function(n){return function(n){return D.push(n),{cancel:function(){D.splice(D.indexOf(n),1)}}}(n)},n.try=function(e,r,t){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.try expected a function");var o;B();try{o=e.apply(r,t||[])}catch(e){return z(),n.reject(e)}return z(),n.resolve(o)},n.delay=function(e){return new n(function(n){setTimeout(n,e)})},n.isPromise=function(e){return!!(e&&e instanceof n)||I(e)},n.flush=function(){return e=k=k||new n,L(),e;var e},n}();function U(){return(U=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n}).apply(this,arguments)}function H(n,e){for(var r=0;r<n.length;r++)try{if(n[r]===e)return r}catch(n){}return-1}var q,G=Object.defineProperty,J=Date.now()%1e9,K=function(){function n(){if(this.name=void 0,this.weakmap=void 0,this.keys=void 0,this.values=void 0,J+=1,this.name="__weakmap_"+(1e9*Math.random()>>>0)+"__"+J,function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var n=new WeakMap,e={};return Object.freeze(e),n.set(e,"__testvalue__"),"__testvalue__"===n.get(e)}catch(n){return!1}}())try{this.weakmap=new WeakMap}catch(n){}this.keys=[],this.values=[]}var e=n.prototype;return e._cleanupClosedWindows=function(){for(var n=this.weakmap,e=this.keys,r=0;r<e.length;r++){var t=e[r];if(P(t)&&b(t)){if(n)try{n.delete(t)}catch(n){}e.splice(r,1),this.values.splice(r,1),r-=1}}},e.isSafeToReadWrite=function(n){if(P(n))return!1;try{n&&n.self,n&&n[this.name]}catch(n){return!1}return!0},e.set=function(n,e){if(!n)throw new Error("WeakMap expected key");var r=this.weakmap;if(r)try{r.set(n,e)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var t=this.name,o=n[t];o&&o[0]===n?o[1]=e:G(n,t,{value:[n,e],writable:!0})}else{this._cleanupClosedWindows();var i=this.keys,a=this.values,u=H(i,n);-1===u?(i.push(n),a.push(e)):a[u]=e}},e.get=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{if(e.has(n))return e.get(n)}catch(n){delete this.weakmap}if(!this.isSafeToReadWrite(n)){this._cleanupClosedWindows();var r=H(this.keys,n);if(-1===r)return;return this.values[r]}var t=n[this.name];if(t&&t[0]===n)return t[1]},e.delete=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{e.delete(n)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var r=n[this.name];r&&r[0]===n&&(r[0]=r[1]=void 0)}else{this._cleanupClosedWindows();var t=this.keys,o=H(t,n);-1!==o&&(t.splice(o,1),this.values.splice(o,1))}},e.has=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{if(e.has(n))return!0}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var r=n[this.name];return!(!r||r[0]!==n)}return this._cleanupClosedWindows(),-1!==H(this.keys,n)},e.getOrSet=function(n,e){if(this.has(n))return this.get(n);var r=e();return this.set(n,r),r},n}();function X(){var n="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,function(){return n.charAt(Math.floor(Math.random()*n.length))})+"_"+function(n){if("function"==typeof btoa)return btoa(n);if("undefined"!=typeof Buffer)return Buffer.from(n,"utf8").toString("base64");throw new Error("Can not find window.btoa or Buffer")}((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}function Y(){}function Z(n){return"[object RegExp]"===Object.prototype.toString.call(n)}function Q(n,e,r){if(n.hasOwnProperty(e))return n[e];var t=r();return n[e]=t,t}Object.create(Error.prototype);var V=5e3,$=2e3,nn=1e4,en=-1,rn={REQUEST:"postrobot_message_request",RESPONSE:"postrobot_message_response",ACK:"postrobot_message_ack"},tn={METHOD:"postrobot_method",HELLO:"postrobot_hello",OPEN_TUNNEL:"postrobot_open_tunnel"},on="__postrobot_bridge__",an="*",un={CROSS_DOMAIN_ZALGO_PROMISE:"cross_domain_zalgo_promise",CROSS_DOMAIN_FUNCTION:"cross_domain_function",CROSS_DOMAIN_WINDOW:"cross_domain_window"};function sn(n){return void 0===n&&(n=window),n!==window?n.__post_robot_10_0_0__:n.__post_robot_10_0_0__=n.__post_robot_10_0_0__||{}}var cn=function(){return{}};function fn(n,e){return void 0===n&&(n="store"),void 0===e&&(e=cn),Q(sn(),n,function(){var n=e();return{has:function(e){return n.hasOwnProperty(e)},get:function(e,r){return n.hasOwnProperty(e)?n[e]:r},set:function(e,r){return n[e]=r,r},del:function(e){delete n[e]},getOrSet:function(e,r){return Q(n,e,r)},reset:function(){n=e()},keys:function(){return Object.keys(n)}}})}var dn=function(){};function wn(){var n=sn();return n.WINDOW_WILDCARD=n.WINDOW_WILDCARD||new dn,n.WINDOW_WILDCARD}function ln(n,e){return void 0===n&&(n="store"),void 0===e&&(e=cn),fn("windowStore").getOrSet(n,function(){var r=new K,t=function(n){return r.getOrSet(n,e)};return{has:function(e){return t(e).hasOwnProperty(n)},get:function(e,r){var o=t(e);return o.hasOwnProperty(n)?o[n]:r},set:function(e,r){return t(e)[n]=r,r},del:function(e){delete t(e)[n]},getOrSet:function(e,r){return Q(t(e),n,r)}}})}function hn(){return fn("instance").getOrSet("instanceID",X)}function mn(n){return ln("helloPromises").getOrSet(n,function(){return new F})}function vn(n,e){return(0,e.send)(n,tn.HELLO,{instanceID:hn()},{domain:an,timeout:-1}).then(function(e){var r=e.origin,t=e.data.instanceID;return mn(n).resolve({win:n,domain:r}),{win:n,domain:r,instanceID:t}})}function pn(n,e){var r=e.send;return ln("windowInstanceIDPromises").getOrSet(n,function(){return vn(n,{send:r}).then(function(n){return n.instanceID})})}function gn(n,e,r){void 0===e&&(e=5e3),void 0===r&&(r="Window");var t=mn(n);return-1!==e&&(t=t.timeout(e,new Error(r+" did not load after "+e+"ms"))),t}function yn(n){ln("knownWindows").set(n,!0)}var En,_n={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"};function On(n){return"object"==typeof n&&null!==n&&"string"==typeof n.__type__}function bn(n){return void 0===n?_n.UNDEFINED:null===n?_n.NULL:Array.isArray(n)?_n.ARRAY:"function"==typeof n?_n.FUNCTION:"object"==typeof n?n instanceof Error?_n.ERROR:"function"==typeof n.then?_n.PROMISE:"[object RegExp]"===Object.prototype.toString.call(n)?_n.REGEX:"[object Date]"===Object.prototype.toString.call(n)?_n.DATE:_n.OBJECT:"string"==typeof n?_n.STRING:"number"==typeof n?_n.NUMBER:"boolean"==typeof n?_n.BOOLEAN:void 0}function Wn(n,e){return{__type__:n,__val__:e}}var Sn,Rn=((En={})[_n.FUNCTION]=function(){},En[_n.ERROR]=function(n){var e=n.message,r=n.stack,t=n.code;return Wn(_n.ERROR,{message:e,stack:r,code:t})},En[_n.PROMISE]=function(){},En[_n.REGEX]=function(n){return Wn(_n.REGEX,n.source)},En[_n.DATE]=function(n){return Wn(_n.DATE,n.toJSON())},En[_n.ARRAY]=function(n){return n},En[_n.OBJECT]=function(n){return n},En[_n.STRING]=function(n){return n},En[_n.NUMBER]=function(n){return n},En[_n.BOOLEAN]=function(n){return n},En[_n.NULL]=function(n){return n},En),An={},Nn=((Sn={})[_n.FUNCTION]=function(){throw new Error("Function serialization is not implemented; nothing to deserialize")},Sn[_n.ERROR]=function(n){var e=n.message,r=n.stack,t=n.code,o=new Error(e);return o.code=t,o.stack=r+"\n\n"+o.stack,o},Sn[_n.PROMISE]=function(){throw new Error("Promise serialization is not implemented; nothing to deserialize")},Sn[_n.REGEX]=function(n){return new RegExp(n)},Sn[_n.DATE]=function(n){return new Date(n)},Sn[_n.ARRAY]=function(n){return n},Sn[_n.OBJECT]=function(n){return n},Sn[_n.STRING]=function(n){return n},Sn[_n.NUMBER]=function(n){return n},Sn[_n.BOOLEAN]=function(n){return n},Sn[_n.NULL]=function(n){return n},Sn),xn={};function Mn(){return!!W(window).match(/MSIE|trident|edge\/12|edge\/13/i)}function jn(n){return!x(window,n)}function Pn(n,e){if(n){if(l()!==j(n))return!0}else if(e&&!m(e))return!0;return!1}function In(n){var e=n.win,r=n.domain;return!(!Mn()||r&&!Pn(r,e)||e&&!jn(e))}function kn(n){var e=(n=n||j(n)).replace(/[^a-zA-Z0-9]+/g,"_");return on+"_"+e}function Tn(){return Boolean(window.name&&window.name===kn(l()))}var Dn=new F(function(n){if(window.document&&window.document.body)return n(window.document.body);var e=setInterval(function(){if(window.document&&window.document.body)return clearInterval(e),n(window.document.body)},10)});function Cn(n){ln("remoteWindowPromises").getOrSet(n,function(){return new F})}function Ln(n){var e=ln("remoteWindowPromises").get(n);if(!e)throw new Error("Remote window promise not found");return e}function Bn(n,e,r){Ln(n).resolve(function(t,o,i){if(t!==n)throw new Error("Remote window does not match window");if(!M(o,e))throw new Error("Remote domain "+o+" does not match domain "+e);r.fireAndForget(i)})}function zn(n,e){Ln(n).reject(e).catch(Y)}function Fn(n){for(var e=n.win,r=n.name,t=n.domain,o=fn("popupWindowsByName"),i=ln("popupWindowsByWin"),a=0,u=o.keys();a<u.length;a++){var s=u[a];b(o.get(s).win)&&o.del(s)}var c=i.getOrSet(e,function(){return r?o.getOrSet(r,function(){return{win:e,name:r}}):{win:e}});if(c.win&&c.win!==e)throw new Error("Different window already linked for window: "+(r||"undefined"));if(r){if(c.name&&c.name!==r)throw new Error("Different window already linked for name "+r+": "+c.name);c.name=r,o.set(r,c)}return t&&(c.domain=t,Cn(e)),i.set(e,c),c}function Un(n){var e,r=n.on,t=n.send,o=n.receiveMessage;e=window.open,window.open=function(n,r,t,o){var a=e.call(this,function(n){if(0!==j(n).indexOf(i.MOCK))return n;throw new Error("Mock urls not supported out of test mode")}(n),r,t,o);return a?(Fn({win:a,name:r,domain:n?j(n):null}),a):a},function(n){var e=n.on,r=n.send,t=n.receiveMessage,o=fn("popupWindowsByName");e(tn.OPEN_TUNNEL,function(n){var i=n.source,a=n.origin,u=n.data,s=fn("bridges").get(a);if(!s)throw new Error("Can not find bridge promise for domain "+a);return s.then(function(n){if(i!==n)throw new Error("Message source does not matched registered bridge for domain "+a);if(!u.name)throw new Error("Register window expected to be passed window name");if(!u.sendMessage)throw new Error("Register window expected to be passed sendMessage method");if(!o.has(u.name))throw new Error("Window with name "+u.name+" does not exist, or was not opened by this window");if(!o.get(u.name).domain)throw new Error("We do not have a registered domain for window "+u.name);if(o.get(u.name).domain!==a)throw new Error("Message origin "+a+" does not matched registered window origin "+o.get(u.name).domain);return Bn(o.get(u.name).win,a,u.sendMessage),{sendMessage:function(n){if(window&&!window.closed){var i=o.get(u.name);if(i)try{t({data:n,origin:i.domain,source:i.win},{on:e,send:r})}catch(n){F.reject(n)}}}}})})}({on:r,send:t,receiveMessage:o}),function(n){var e=n.send;sn(window).openTunnelToParent=function(n){var r=n.name,t=n.source,o=n.canary,i=n.sendMessage,a=fn("tunnelWindows"),u=c(window);if(!u)throw new Error("No parent window found to open tunnel to");var s=function(n){var e=n.name,r=n.source,t=n.canary,o=n.sendMessage;!function(){for(var n=fn("tunnelWindows"),e=0,r=n.keys();e<r.length;e++){var t=r[e],o=n[t];try{o.source}catch(e){n.del(t);continue}b(o.source)&&n.del(t)}}();var i=X();return fn("tunnelWindows").set(i,{name:e,source:r,canary:t,sendMessage:o}),i}({name:r,source:t,canary:o,sendMessage:i});return e(u,tn.OPEN_TUNNEL,{name:r,sendMessage:function(){var n=a.get(s);try{n&&n.source}catch(n){return void a.del(s)}if(n&&n.source&&!b(n.source)){try{n.canary()}catch(n){return}n.sendMessage.apply(this,arguments)}}},{domain:an})}}({on:r,send:t}),function(n){var e=n.on,r=n.send,t=n.receiveMessage;F.try(function(){var n,o=f(window);if(o&&In({win:o}))return Cn(o),(n=o,ln("remoteBridgeAwaiters").getOrSet(n,function(){return F.try(function(){var e=S(n,kn(l()));if(!e)throw new Error("Bridge not found for domain: "+l());return m(e)&&sn(e)?e:new F(function(n,r){var t,o;t=setInterval(function(){if(e&&m(e)&&sn(e))return clearInterval(t),clearTimeout(o),n(e)},100),o=setTimeout(function(){return clearInterval(t),r(new Error("Bridge not found for domain: "+l()))},2e3)})})})).then(function(n){return window.name?sn(n).openTunnelToParent({name:window.name,source:window,canary:function(){},sendMessage:function(n){if(window&&!window.closed)try{t({data:n,origin:this.origin,source:this.source},{on:e,send:r})}catch(n){F.reject(n)}}}).then(function(n){var e=n.source,r=n.origin,t=n.data;if(e!==o)throw new Error("Source does not match opener");Bn(e,r,t.sendMessage)}).catch(function(n){throw zn(o,n),n}):zn(o,new Error("Can not register with opener: window does not have a name"))})})}({on:r,send:t,receiveMessage:o})}function Hn(){for(var n=fn("idToProxyWindow"),e=0,r=n.keys();e<r.length;e++){var t=r[e];n.get(t).shouldClean()&&n.del(t)}}var qn=function(){function n(n,e,r){var t=r.send;this.isProxyWindow=!0,this.serializedWindow=void 0,this.actualWindow=void 0,this.actualWindowPromise=void 0,this.send=void 0,this.serializedWindow=n,this.actualWindowPromise=new F,e&&this.setWindow(e),this.serializedWindow.getInstanceID=function(n){var e={};function r(){for(var r=arguments.length,t=new Array(r),o=0;o<r;o++)t[o]=arguments[o];var i=function(n){try{return JSON.stringify(Array.prototype.slice.call(n),function(n,e){return"function"==typeof e?"memoize["+function(n){if(q=q||new K,null==n||"object"!=typeof n&&"function"!=typeof n)throw new Error("Invalid object");var e=q.get(n);return e||(e=typeof n+":"+X(),q.set(n,e)),e}(e)+"]":e})}catch(n){throw new Error("Arguments not serializable -- can not be used to memoize")}}(t);return e.hasOwnProperty(i)?e[i]:(e[i]=n.apply(this,arguments).finally(function(){delete e[i]}),e[i])}return r.reset=function(){e={}},r}(this.serializedWindow.getInstanceID),this.send=t}var e=n.prototype;return e.getType=function(){return this.serializedWindow.type},e.isPopup=function(){return"popup"===this.getType()},e.isIframe=function(){return"iframe"===this.getType()},e.setLocation=function(n){var e=this;return F.try(function(){if(!e.actualWindow)return e.serializedWindow.setLocation(n);e.actualWindow.location=n}).then(function(){return e})},e.setName=function(n){var e=this;return F.try(function(){if(!e.actualWindow)return e.serializedWindow.setName(n);if(!m(e.actualWindow))throw new Error("Can not set name for window on different domain");e.actualWindow.name=n,e.actualWindow.frameElement&&e.actualWindow.frameElement.setAttribute("name",n),Fn({win:e.actualWindow,name:n})}).then(function(){return e})},e.close=function(){var n=this;return F.try(function(){if(!n.actualWindow)return n.serializedWindow.close();n.actualWindow.close()}).then(function(){return n})},e.focus=function(){var n=this;return F.try(function(){return n.actualWindow&&n.actualWindow.focus(),n.serializedWindow.focus()}).then(function(){return n})},e.isClosed=function(){var n=this;return F.try(function(){return n.actualWindow?b(n.actualWindow):n.serializedWindow.isClosed()})},e.getWindow=function(){return this.actualWindow},e.setWindow=function(n){this.actualWindow=n,this.actualWindowPromise.resolve(n)},e.awaitWindow=function(){return this.actualWindowPromise},e.matchWindow=function(n){var e=this;return F.try(function(){return e.actualWindow?n===e.actualWindow:F.all([e.getInstanceID(),pn(n,{send:e.send})]).then(function(r){var t=r[0]===r[1];return t&&e.setWindow(n),t})})},e.unwrap=function(){return this.actualWindow||this},e.getInstanceID=function(){return this.actualWindow?pn(this.actualWindow,{send:this.send}):this.serializedWindow.getInstanceID()},e.serialize=function(){return this.serializedWindow},e.shouldClean=function(){return this.actualWindow&&b(this.actualWindow)},n.unwrap=function(e){return n.isProxyWindow(e)?e.unwrap():e},n.serialize=function(e,r){var t=r.send;return Hn(),n.toProxyWindow(e,{send:t}).serialize()},n.deserialize=function(e,r){var t=r.on,o=r.send;return Hn(),fn("idToProxyWindow").getOrSet(e.id,function(){return new n(e,null,{on:t,send:o})})},n.isProxyWindow=function(n){return Boolean(n&&!P(n)&&n.isProxyWindow)},n.toProxyWindow=function(e,r){var t=r.send;return Hn(),n.isProxyWindow(e)?e:ln("winToProxyWindow").getOrSet(e,function(){var r=X();return fn("idToProxyWindow").set(r,new n({id:r,type:f(e)?"popup":"iframe",getInstanceID:function(){return pn(e,{send:t})},close:function(){return F.try(function(){e.close()})},focus:function(){return F.try(function(){e.focus()})},isClosed:function(){return F.try(function(){return b(e)})},setLocation:function(n){return F.try(function(){if(m(e))try{if(e.location&&"function"==typeof e.location.replace)return void e.location.replace(n)}catch(n){}e.location=n})},setName:function(n){return F.try(function(){Fn({win:e,name:n}),e.name=n})}},e,{send:t}))})},n}();function Gn(n,e,r,t,o){var i=ln("methodStore"),a=fn("proxyWindowMethods");qn.isProxyWindow(t)?a.set(n,{val:e,name:r,domain:o,source:t}):(a.del(n),i.getOrSet(t,function(){return{}})[n]={domain:o,name:r,val:e,source:t})}function Jn(n,e){var r=ln("methodStore"),t=fn("proxyWindowMethods");return r.getOrSet(n,function(){return{}})[e]||t.get(e)}function Kn(n,e,r,t,o){!function(n){var e=o.on;fn("builtinListeners").getOrSet("functionCalls",function(){return e(tn.METHOD,{domain:an},function(n){var e=n.source,r=n.origin,t=n.data,o=t.id,i=t.name,a=Jn(e,o);if(!a)throw new Error("Could not find method '"+t.name+"' with id: "+t.id+" in "+l(window));var u=a.source,s=a.domain,c=a.val;return F.try(function(){if(!M(s,r))throw new Error("Method '"+t.name+"' domain "+JSON.stringify(Z(a.domain)?a.domain.source:a.domain)+" does not match origin "+r+" in "+l(window));if(qn.isProxyWindow(u))return u.matchWindow(e).then(function(n){if(!n)throw new Error("Method call '"+t.name+"' failed - proxy window does not match source in "+l(window))})}).then(function(){return c.apply({source:e,origin:r},t.args)},function(n){return F.try(function(){if(c.onError)return c.onError(n)}).then(function(){throw n})}).then(function(n){return{result:n,id:o,name:i}})})})}();var i=r.__id__||X();n=qn.unwrap(n);var a=r.__name__||r.name||t;return qn.isProxyWindow(n)?(Gn(i,r,a,n,e),n.awaitWindow().then(function(n){Gn(i,r,a,n,e)})):Gn(i,r,a,n,e),Wn(un.CROSS_DOMAIN_FUNCTION,{id:i,name:a})}function Xn(n,e,r,t){var o,i=t.on,a=t.send;return function(n,e){void 0===e&&(e=An);var r=JSON.stringify(n,function(n){var r=this[n];if(On(this))return r;var t=bn(r);if(!t)return r;var o=e[t]||Rn[t];return o?o(r,n):r});return void 0===r?_n.UNDEFINED:r}(r,((o={})[_n.PROMISE]=function(r,t){return function(n,e,r,t,o){var i=o.on,a=o.send;return Wn(un.CROSS_DOMAIN_ZALGO_PROMISE,{then:Kn(n,e,function(n,e){return r.then(n,e)},t,{on:i,send:a})})}(n,e,r,t,{on:i,send:a})},o[_n.FUNCTION]=function(r,t){return Kn(n,e,r,t,{on:i,send:a})},o[_n.OBJECT]=function(n){return P(n)||qn.isProxyWindow(n)?function(n,e,r,t){var o=t.send;return Wn(un.CROSS_DOMAIN_WINDOW,qn.serialize(r,{send:o}))}(0,0,n,{on:i,send:a}):n},o))}function Yn(n,e,r,t){var o,i=t.on,a=t.send;return function(n,e){if(void 0===e&&(e=xn),n!==_n.UNDEFINED)return JSON.parse(n,function(n,r){if(On(this))return r;var t,o;if(On(r)?(t=r.__type__,o=r.__val__):(t=bn(r),o=r),!t)return o;var i=e[t]||Nn[t];return i?i(o,n):o})}(r,((o={})[un.CROSS_DOMAIN_ZALGO_PROMISE]=function(n){return e=n.then,new F(e);var e},o[un.CROSS_DOMAIN_FUNCTION]=function(r){return function(n,e,r,t){var o=r.id,i=r.name,a=t.send,u=function(r){function t(){var u=arguments;return qn.toProxyWindow(n,{send:a}).awaitWindow().then(function(n){var s=Jn(n,o);return s&&s.val!==t?s.val.apply({source:window,origin:l()},u):a(n,tn.METHOD,{id:o,name:i,args:Array.prototype.slice.call(u)},{domain:e,fireAndForget:r.fireAndForget}).then(function(n){if(!r.fireAndForget)return n.data.result})}).catch(function(n){throw n})}return void 0===r&&(r={}),t.__name__=i,t.__origin__=e,t.__source__=n,t.__id__=o,t.origin=e,t},s=u();return s.fireAndForget=u({fireAndForget:!0}),s}(n,e,r,{on:i,send:a})},o[un.CROSS_DOMAIN_WINDOW]=function(n){return function(n,e,r,t){var o=t.on,i=t.send;return qn.deserialize(r,{on:o,send:i})}(0,0,n,{on:i,send:a})},o))}var Zn={};function Qn(n,e,r,t){var o,i=t.on,a=t.send;if(b(n))throw new Error("Window is closed");for(var u,s=Xn(n,e,((o={}).__post_robot_10_0_0__=U({id:X()},r),o),{on:i,send:a}),c=!1,f=0,d=Object.keys(Zn);f<d.length;f++){var w=d[f];try{Zn[w](n,s,e),c=!0}catch(n){u=u||n}}if(!c)throw u}Zn.postrobot_post_message=function(n,e,r){(Array.isArray(r)?r:"string"==typeof r?[r]:[an]).map(function(e){if(0===e.indexOf(i.MOCK)){if(window.location.protocol===i.FILE)return an;if(!h(n))throw new Error("Attempting to send messsage to mock domain "+e+", but window is actually cross-domain");return w(n)}return 0===e.indexOf(i.FILE)?an:e}).forEach(function(r){n.postMessage(e,r)})},Zn.postrobot_bridge=function(n,e,r){if(Mn()||Tn()){if(m(n))throw new Error("Post message through bridge disabled between same domain windows");if(!1!==x(window,n))throw new Error("Can only use bridge to communicate between two different windows, not between frames");!function(n,e,r){var t=R(window,n),o=R(n,window);if(!t&&!o)throw new Error("Can only send messages to and from parent and popup windows");Ln(n).then(function(t){return t(n,e,r)})}(n,r,e)}},Zn.postrobot_global=function(n,e){if(W(window).match(/MSIE|rv:11|trident|edge\/12|edge\/13/i)){if(!m(n))throw new Error("Post message through global disabled between different domain windows");if(!1!==x(window,n))throw new Error("Can only use global to communicate between two different windows, not between frames");var r=sn(n);if(!r)throw new Error("Can not find postRobot global on foreign window");r.receiveMessage({source:window,origin:l(),data:e})}};var Vn,$n="__domain_regex__";function ne(n){return fn("responseListeners").get(n)}function ee(n){fn("responseListeners").del(n)}function re(n){return fn("erroredResponseListeners").has(n)}function te(n){var e=n.name,r=n.win,t=n.domain,o=ln("requestListeners");if(r===an&&(r=null),t===an&&(t=null),!e)throw new Error("Name required to get request listener");for(var i=0,a=[r,wn()];i<a.length;i++){var u=a[i];if(u){var s=o.get(u);if(s){var c=s[e];if(c){if(t&&"string"==typeof t){if(c[t])return c[t];if(c[$n])for(var f=0,d=c[$n];f<d.length;f++){var w=d[f],l=w.regex,h=w.listener;if(M(l,t))return h}}if(c[an])return c[an]}}}}}var oe,ie=((Vn={})[rn.REQUEST]=function(n,e,r,t){var o=t.on,i=t.send,a=te({name:r.name,win:n,domain:e});function u(t,a,u){void 0===u&&(u={}),r.fireAndForget||b(n)||Qn(n,e,U({type:t,ack:a,hash:r.hash,name:r.name},u),{on:o,send:i})}return r.name===tn.METHOD&&r.data&&"string"==typeof r.data.name?r.data.name:r.name,F.all([u(rn.ACK),F.try(function(){if(!a)throw new Error("No handler found for post message: "+r.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!M(a.domain,e))throw new Error("Request origin "+e+" does not match domain "+a.domain.toString());var t=r.data;return a.handler({source:n,origin:e,data:t})}).then(function(n){return u(rn.RESPONSE,"success",{data:n})},function(n){return u(rn.RESPONSE,"error",{error:n})})]).then(Y).catch(function(n){if(a&&a.handleError)return a.handleError(n);throw n})},Vn[rn.ACK]=function(n,e,r){if(!re(r.hash)){var t=ne(r.hash);if(!t)throw new Error("No handler found for post message ack for message: "+r.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!M(t.domain,e))throw new Error("Ack origin "+e+" does not match domain "+t.domain.toString());if(n!==t.win)throw new Error("Ack source does not match registered window");t.ack=!0}},Vn[rn.RESPONSE]=function(n,e,r){if(!re(r.hash)){var t,i=ne(r.hash);if(!i)throw new Error("No handler found for post message response for message: "+r.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!M(i.domain,e))throw new Error("Response origin "+e+" does not match domain "+(t=i.domain,Array.isArray(t)?"("+t.join(" | ")+")":o(t)?"RegExp("+t.toString():t.toString()));if(n!==i.win)throw new Error("Response source does not match registered window");ee(r.hash),r.name===tn.METHOD&&r.data&&"string"==typeof r.data.name?r.data.name:r.name,"error"===r.ack?i.promise.reject(r.error):"success"===r.ack&&i.promise.resolve({source:n,origin:e,data:r.data})}},Vn);function ae(n,e){var r=e.on,t=e.send,o=fn("receivedMessages");if(!window||window.closed)throw new Error("Message recieved in closed window");try{if(!n.source)return}catch(n){return}var i=n.source,a=n.origin,u=function(n,e,r,t){var o,i=t.on,a=t.send;try{o=Yn(e,r,n,{on:i,send:a})}catch(n){return}if(o&&"object"==typeof o&&null!==o&&(o=o.__post_robot_10_0_0__)&&"object"==typeof o&&null!==o&&o.type&&"string"==typeof o.type&&ie[o.type])return o}(n.data,i,a,{on:r,send:t});u&&(yn(i),o.has(u.id)||(o.set(u.id,!0),b(i)&&!u.fireAndForget||ie[u.type](i,a,u,{on:r,send:t})))}function ue(n,e,r){if(!n)throw new Error("Expected name");if("function"==typeof e&&(r=e,e={}),!r)throw new Error("Expected handler");(e=e||{}).name=n,e.handler=r||e.handler;var t=e.window,o=e.domain,i=function n(e,r){var t=e.name,o=e.win,i=e.domain,a=ln("requestListeners");if(!t||"string"!=typeof t)throw new Error("Name required to add request listener");if(Array.isArray(o)){for(var u=[],s=0,c=o;s<c.length;s++){var f=c[s];u.push(n({name:t,domain:i,win:f},r))}return{cancel:function(){for(var n=0;n<u.length;n++)u[n].cancel()}}}if(Array.isArray(i)){for(var d=[],w=0,l=i;w<l.length;w++){var h=l[w];d.push(n({name:t,win:o,domain:h},r))}return{cancel:function(){for(var n=0;n<d.length;n++)d[n].cancel()}}}var m=te({name:t,win:o,domain:i});if(o&&o!==an||(o=wn()),i=i||an,m)throw o&&i?new Error("Request listener already exists for "+t+" on domain "+i.toString()+" for "+(o===wn()?"wildcard":"specified")+" window"):o?new Error("Request listener already exists for "+t+" for "+(o===wn()?"wildcard":"specified")+" window"):i?new Error("Request listener already exists for "+t+" on domain "+i.toString()):new Error("Request listener already exists for "+t);var v,p,g=a.getOrSet(o,function(){return{}}),y=Q(g,t,function(){return{}}),E=i.toString();return Z(i)?(v=Q(y,$n,function(){return[]}),p={regex:i,listener:r},v.push(p)):y[E]=r,{cancel:function(){delete y[E],p&&(v.splice(v.indexOf(p,1)),v.length||delete y[$n]),Object.keys(y).length||delete g[t],o&&!Object.keys(g).length&&a.del(o)}}}({name:n,win:t,domain:o},{handler:e.handler,handleError:e.errorHandler||function(n){throw n},window:t,domain:o||an,name:n});return{cancel:function(){i.cancel()}}}function se(n,e,r){"function"==typeof(e=e||{})&&(r=e,e={});var t,o=new F;return e.errorHandler=function(n){t.cancel(),o.reject(n)},t=ue(n,e,function(n){if(t.cancel(),o.resolve(n),r)return r(n)}),o.cancel=t.cancel,o}function ce(n,e,r,t){var o=(t=t||{}).domain||an,i=t.timeout||en,a=t.timeout||V,u=t.fireAndForget||!1;return F.try(function(){if(!e)throw new Error("Expected name");if(o&&"string"!=typeof o&&!Array.isArray(o)&&!Z(o))throw new TypeError("Expected domain to be a string, array, or regex");if(b(n))throw new Error("Target window is closed");var t=ln("requestPromises").getOrSet(n,function(){return[]}),s=F.try(function(){return function(n,e){var r=A(e);if(r)return r===n;if(e===n)return!1;if(y(e)===e)return!1;for(var t=0,o=p(n);t<o.length;t++)if(o[t]===e)return!0;return!1}(window,n)?gn(n,a):Z(o)?vn(n,{send:ce}):void 0}).then(function(a){var c=(void 0===a?{}:a).domain;if(Z(o)){if(!M(o,c))throw new Error("Remote window domain "+c+" does not match regex: "+o.source);o=c}e===tn.METHOD&&r&&"string"==typeof r.name&&r.name;var f=!1,d=new F;d.finally(function(){f=!0,t.splice(t.indexOf(s,1))}).catch(Y);var w=e+"_"+X();if(Qn(n,o,{type:rn.REQUEST,hash:w,name:e,data:r,fireAndForget:u},{on:ue,send:ce}),u)return d.resolve();d.catch(function(){!function(n){fn("erroredResponseListeners").set(n,!0)}(w),ee(w)});var h={name:e,win:n,domain:o,promise:d};!function(n,e){fn("responseListeners").set(n,e)}(w,h);var m=function(n){return ln("knownWindows").get(n,!1)}(n)?nn:$,v=i,p=m,g=v,y=100;return setTimeout(function r(){if(!f){if(b(n))return h.ack?d.reject(new Error("Window closed for "+e+" before response")):d.reject(new Error("Window closed for "+e+" before ack"));if(p=Math.max(p-y,0),-1!==g&&(g=Math.max(g-y,0)),h.ack){if(-1===g)return;y=Math.min(g,2e3)}else{if(0===p)return d.reject(new Error("No ack for postMessage "+e+" in "+l()+" in "+m+"ms"));if(0===g)return d.reject(new Error("No response for postMessage "+e+" in "+l()+" in "+v+"ms"))}setTimeout(r,y)}},y),d});return t.push(s),s})}function fe(n,e,r){return Xn(n,e,r,{on:ue,send:ce})}function de(n,e,r){return Yn(n,e,r,{on:ue,send:ce})}function we(n){return qn.toProxyWindow(n,{send:ce})}function le(){var n,e,r,t;sn().initialized||(sn().initialized=!0,function(n){var e=n.on,r=n.send;fn().getOrSet("postMessageListeners",function(){return n=window,t=function(n){!function(n,e){var r=e.on,t=e.send;try{n.source}catch(n){return}var o={source:n.source||n.sourceElement,origin:n.origin||n.originalEvent&&n.originalEvent.origin,data:n.data};if(o.source){if(!o.origin)throw new Error("Post message did not have origin domain");ae(o,{on:r,send:t})}}(n,{on:e,send:r})},n.addEventListener("message",t),{cancel:function(){n.removeEventListener("message",t)}};var n,t})}({on:ue,send:ce}),Un({on:ue,send:ce,receiveMessage:ae}),function(n){var e=n.on,r=n.send;fn("builtinListeners").getOrSet("helloListener",function(){var n=e(tn.HELLO,{domain:an},function(n){var e=n.source,r=n.origin;return mn(e).resolve({win:e,domain:r}),{instanceID:hn()}}),t=A();return t&&vn(t,{send:r}).catch(Y),n})}({on:ue,send:ce}),e=(n={on:ue,send:ce}).on,r=n.send,(t=sn()).receiveMessage=t.receiveMessage||function(n){return ae(n,{on:e,send:r})})}function he(n){for(var e=0,r=ln("requestPromises").get(n,[]);e<r.length;e++)r[e].reject(new Error("Window cleaned up before response")).catch(Y)}r.d(e,"bridge",function(){return oe}),r.d(e,"Promise",function(){return F}),r.d(e,"TYPES",function(){return!0}),r.d(e,"ProxyWindow",function(){return qn}),r.d(e,"setup",function(){return le}),r.d(e,"serializeMessage",function(){return fe}),r.d(e,"deserializeMessage",function(){return de}),r.d(e,"toProxyWindow",function(){return we}),r.d(e,"on",function(){return ue}),r.d(e,"once",function(){return se}),r.d(e,"send",function(){return ce}),r.d(e,"markWindowKnown",function(){return yn}),r.d(e,"cleanUpWindow",function(){return he}),oe={setupBridge:Un,openBridge:function(n,e){var r=fn("bridges"),t=fn("bridgeFrames");return e=e||j(n),r.getOrSet(e,function(){return F.try(function(){if(l()===e)throw new Error("Can not open bridge on the same domain as current domain: "+e);var r=kn(e);if(S(window,r))throw new Error("Frame with name "+r+" already exists on page");var o=function(n,e){var r=document.createElement("iframe");return r.setAttribute("name",n),r.setAttribute("id",n),r.setAttribute("style","display: none; margin: 0; padding: 0; border: 0px none; overflow: hidden;"),r.setAttribute("frameborder","0"),r.setAttribute("border","0"),r.setAttribute("scrolling","no"),r.setAttribute("allowTransparency","true"),r.setAttribute("tabindex","-1"),r.setAttribute("hidden","true"),r.setAttribute("title",""),r.setAttribute("role","presentation"),r.src=e,r}(r,n);return t.set(e,o),Dn.then(function(e){e.appendChild(o);var r=o.contentWindow;return new F(function(n,e){o.addEventListener("load",n),o.addEventListener("error",e)}).then(function(){return gn(r,5e3,"Bridge "+n)}).then(function(){return r})})})})},linkWindow:Fn,linkUrl:function(n,e){Fn({win:n,domain:j(e)})},isBridge:Tn,needsBridge:In,needsBridgeForBrowser:Mn,hasBridge:function(n,e){return fn("bridges").has(e||j(n))},needsBridgeForWin:jn,needsBridgeForDomain:Pn,destroyBridges:function(){for(var n=fn("bridges"),e=fn("bridgeFrames"),r=0,t=e.keys();r<t.length;r++){var o=t[r],i=e.get(o);i&&i.parentNode&&i.parentNode.removeChild(i)}e.reset(),n.reset()}},le()}])}); | ||
//# sourceMappingURL=post-robot.ie.min.js.map |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("postRobot",[],t):"object"==typeof exports?exports.postRobot=t():n.postRobot=t()}("undefined"!=typeof self?self:this,function(){return function(n){var t={};function e(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:r})},e.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return e.d(t,"a",t),t},e.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},e.p="",e(e.s=9)}([function(n,t,e){"use strict";var r=e(10);e.d(t,"getActualDomain",function(){return r.a}),e.d(t,"getAncestor",function(){return r.b}),e.d(t,"getDomain",function(){return r.c}),e.d(t,"getOpener",function(){return r.d}),e.d(t,"getUserAgent",function(){return r.e}),e.d(t,"isActuallySameDomain",function(){return r.f}),e.d(t,"isAncestor",function(){return r.g}),e.d(t,"isSameDomain",function(){return r.h}),e.d(t,"isWindow",function(){return r.i}),e.d(t,"isWindowClosed",function(){return r.j}),e.d(t,"linkFrameWindow",function(){return r.k}),e.d(t,"matchDomain",function(){return r.l}),e.d(t,"stringifyDomainPattern",function(){return r.m});var o=e(11);e.n(o),e.o(o,"WINDOW_TYPE")&&e.d(t,"WINDOW_TYPE",function(){return o.WINDOW_TYPE});var i=e(5);e.d(t,"WINDOW_TYPE",function(){return i.c})},function(n,t,e){"use strict";function r(n){try{if(!n)return!1;if("undefined"!=typeof Promise&&n instanceof Promise)return!0;if("undefined"!=typeof window&&window.Window&&n instanceof window.Window)return!1;if("undefined"!=typeof window&&window.constructor&&n instanceof window.constructor)return!1;var t={}.toString;if(t){var e=t.call(n);if("[object Window]"===e||"[object global]"===e||"[object DOMWindow]"===e)return!1}if("function"==typeof n.then)return!0}catch(n){return!1}return!1}function o(){var n=void 0;if("undefined"!=typeof window)n=window;else{if("undefined"==typeof window)throw new TypeError("Can not find global");n=window}var t=n.__zalgopromise__=n.__zalgopromise__||{};return t.flushPromises=t.flushPromises||[],t.activeCount=t.activeCount||0,t.possiblyUnhandledPromiseHandlers=t.possiblyUnhandledPromiseHandlers||[],t.dispatchedErrors=t.dispatchedErrors||[],t}var i=function(){function n(t){var e=this;if(function(t,e){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this),this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],t){var r=void 0,o=void 0,i=!1,a=!1,u=!1;try{t(function(n){u?e.resolve(n):(i=!0,r=n)},function(n){u?e.reject(n):(a=!0,o=n)})}catch(n){return void this.reject(n)}u=!0,i?this.resolve(r):a&&this.reject(o)}}return n.prototype.resolve=function(n){if(this.resolved||this.rejected)return this;if(r(n))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=n,this.dispatch(),this},n.prototype.reject=function(n){var t=this;if(this.resolved||this.rejected)return this;if(r(n))throw new Error("Can not reject promise with another promise");if(!n){var e=n&&"function"==typeof n.toString?n.toString():Object.prototype.toString.call(n);n=new Error("Expected reject to be called with Error, got "+e)}return this.rejected=!0,this.error=n,this.errorHandled||setTimeout(function(){t.errorHandled||function(n,t){if(-1===o().dispatchedErrors.indexOf(n)){o().dispatchedErrors.push(n),setTimeout(function(){throw n},1);for(var e=0;e<o().possiblyUnhandledPromiseHandlers.length;e++)o().possiblyUnhandledPromiseHandlers[e](n,t)}}(n,t)},1),this.dispatch(),this},n.prototype.asyncReject=function(n){return this.errorHandled=!0,this.reject(n),this},n.prototype.dispatch=function(){var t=this,e=this.dispatching,i=this.resolved,a=this.rejected,u=this.handlers;if(!e&&(i||a)){this.dispatching=!0,o().activeCount+=1;for(var c=function(e){var o=u[e],c=o.onSuccess,s=o.onError,f=o.promise,d=void 0;if(i)try{d=c?c(t.value):t.value}catch(n){return f.reject(n),"continue"}else if(a){if(!s)return f.reject(t.error),"continue";try{d=s(t.error)}catch(n){return f.reject(n),"continue"}}d instanceof n&&(d.resolved||d.rejected)?(d.resolved?f.resolve(d.value):f.reject(d.error),d.errorHandled=!0):r(d)?d instanceof n&&(d.resolved||d.rejected)?d.resolved?f.resolve(d.value):f.reject(d.error):d.then(function(n){f.resolve(n)},function(n){f.reject(n)}):f.resolve(d)},s=0;s<u.length;s++)c(s);u.length=0,this.dispatching=!1,o().activeCount-=1,0===o().activeCount&&n.flushQueue()}},n.prototype.then=function(t,e){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.then expected a function for success handler");if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.then expected a function for error handler");var r=new n;return this.handlers.push({promise:r,onSuccess:t,onError:e}),this.errorHandled=!0,this.dispatch(),r},n.prototype.catch=function(n){return this.then(void 0,n)},n.prototype.finally=function(t){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.finally expected a function");return this.then(function(e){return n.try(t).then(function(){return e})},function(e){return n.try(t).then(function(){throw e})})},n.prototype.timeout=function(n,t){var e=this;if(this.resolved||this.rejected)return this;var r=setTimeout(function(){e.resolved||e.rejected||e.reject(t||new Error("Promise timed out after "+n+"ms"))},n);return this.then(function(n){return clearTimeout(r),n})},n.prototype.toPromise=function(){if("undefined"==typeof Promise)throw new TypeError("Could not find Promise");return Promise.resolve(this)},n.resolve=function(t){return t instanceof n?t:r(t)?new n(function(n,e){return t.then(n,e)}):(new n).resolve(t)},n.reject=function(t){return(new n).reject(t)},n.asyncReject=function(t){return(new n).asyncReject(t)},n.all=function(t){var e=new n,o=t.length,i=[];if(!o)return e.resolve(i),e;for(var a=function(a){var u=t[a];if(u instanceof n){if(u.resolved)return i[a]=u.value,o-=1,"continue"}else if(!r(u))return i[a]=u,o-=1,"continue";n.resolve(u).then(function(n){i[a]=n,0==(o-=1)&&e.resolve(i)},function(n){e.reject(n)})},u=0;u<t.length;u++)a(u);return 0===o&&e.resolve(i),e},n.hash=function(t){var e={};return n.all(Object.keys(t).map(function(r){return n.resolve(t[r]).then(function(n){e[r]=n})})).then(function(){return e})},n.map=function(t,e){return n.all(t.map(e))},n.onPossiblyUnhandledException=function(n){return function(n){return o().possiblyUnhandledPromiseHandlers.push(n),{cancel:function(){o().possiblyUnhandledPromiseHandlers.splice(o().possiblyUnhandledPromiseHandlers.indexOf(n),1)}}}(n)},n.try=function(t,e,r){if(t&&"function"!=typeof t&&!t.call)throw new Error("Promise.try expected a function");var o=void 0;try{o=t.apply(e,r||[])}catch(t){return n.reject(t)}return n.resolve(o)},n.delay=function(t){return new n(function(n){setTimeout(n,t)})},n.isPromise=function(t){return!!(t&&t instanceof n)||r(t)},n.flush=function(){var t=new n;return o().flushPromises.push(t),0===o().activeCount&&n.flushQueue(),t},n.flushQueue=function(){var n=o().flushPromises;o().flushPromises=[];for(var t=0,e=null==n?0:n.length;t<e;t++)n[t].resolve()},n}();e.d(t,"a",function(){return i})},function(n,t,e){"use strict";e(6);var r=e(7);e.d(t,"addEventListener",function(){return r.a}),e(12),e(13),e(8);var o=e(3);e.d(t,"getOrSet",function(){return o.d}),e.d(t,"isRegex",function(){return o.f}),e.d(t,"memoizePromise",function(){return o.h}),e.d(t,"noop",function(){return o.i}),e.d(t,"once",function(){return o.j}),e.d(t,"safeInterval",function(){return o.m}),e.d(t,"stringifyError",function(){return o.o}),e.d(t,"uniqueID",function(){return o.q}),e.d(t,"weakMapMemoizePromise",function(){return o.r}),e(14);var i=e(15);e.n(i),e(16),e(17),e(18)},function(n,t,e){"use strict";t.q=a,t.c=function(){if("undefined"!=typeof window)return window;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("No global found")},t.g=function(n){var t=this,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=new o.a;function i(){for(var t=arguments.length,o=Array(t),i=0;i<t;i++)o[i]=arguments[i];var a=r.getOrSet(e.thisNamespace?this:n,function(){return{}}),u=c(o),s=e.time;if(a[u]&&s&&Date.now()-a[u].time<s&&delete a[u],a[u])return a[u].value;var f=Date.now(),d=n.apply(this,arguments);return a[u]={time:f,value:d},a[u].value}return i.reset=function(){r.delete(e.thisNamespace?t:n)},e.name&&(i.displayName=e.name+":memoized"),i},t.h=function(n){var t={};function e(){for(var e=arguments.length,r=Array(e),o=0;o<e;o++)r[o]=arguments[o];var i=c(r);return t.hasOwnProperty(i)?t[i]:(t[i]=n.apply(this,arguments).finally(function(){delete t[i]}),t[i])}return e.reset=function(){t={}},e},t.k=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};function e(){return r.a.try(n,this,arguments)}return t.name&&(e.displayName=t.name+":promisified"),e},t.e=function(n,t){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=n.__inline_memoize_cache__=n.__inline_memoize_cache__||{},o=c(e);return r.hasOwnProperty(o)?r[o]:r[o]=t.apply(void 0,e)},t.i=function(){},t.j=function(n){var t=!1;return function(){if(!t)return t=!0,n.apply(this,arguments)}},t.o=function n(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(e>=3)return"stringifyError stack overflow";try{if(!t)return"<unknown error: "+Object.prototype.toString.call(t)+">";if("string"==typeof t)return t;if(t instanceof Error){var r=t&&t.stack,o=t&&t.message;if(r&&o)return-1!==r.indexOf(o)?r:o+"\n"+r;if(r)return r;if(o)return o}return"function"==typeof t.toString?t.toString():Object.prototype.toString.call(t)}catch(t){return"Error while stringifying error: "+n(t,e+1)}},t.n=function(n){return"string"==typeof n?n:n&&"function"==typeof n.toString?n.toString():Object.prototype.toString.call(n)},t.b=function(n,t){if(!t)return n;if(Object.assign)return Object.assign(n,t);for(var e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);return n},t.m=function(n,t){var e=void 0;return function r(){e=setTimeout(function(){n(),r()},t)}(),{cancel:function(){clearTimeout(e)}}},t.a=function(n){return n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()},t.f=function(n){return"[object RegExp]"===Object.prototype.toString.call(n)},e.d(t,"r",function(){return s}),t.d=function(n,t,e){if(n.hasOwnProperty(t))return n[t];var r=e();return n[t]=r,r},t.p=function(n){var t=void 0,e=void 0;try{t=n()}catch(n){e=n}return{result:t,error:e}},t.l=function(n,t){var e=n.indexOf(t);-1!==e&&n.splice(e,1)};var r=e(1),o=e(4),i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function a(){var n="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,function(){return n.charAt(Math.floor(Math.random()*n.length))})+"_"+function(n){if("function"==typeof btoa)return btoa(n);if("undefined"!=typeof Buffer)return Buffer.from(n,"utf8").toString("base64");throw new Error("Can not find window.btoa or Buffer")}((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}var u=void 0;function c(n){try{return JSON.stringify(Array.prototype.slice.call(n),function(n,t){return"function"==typeof t?"memoize["+function(n){if(u=u||new o.a,null===n||void 0===n||"object"!==(void 0===n?"undefined":i(n))&&"function"!=typeof n)throw new Error("Invalid object");var t=u.get(n);return t||(t=(void 0===n?"undefined":i(n))+":"+a(),u.set(n,t)),t}(t)+"]":t})}catch(n){throw new Error("Arguments not serializable -- can not be used to memoize")}}var s=function(n){var t=new o.a;return function(e){var r=this;return t.getOrSet(e,function(){return n.call(r,e).finally(function(){t.delete(e)})})}}},function(n,t,e){"use strict";e.d({},"WeakMap",function(){return u});var r=e(0);function o(n,t){for(var e=0;e<n.length;e++)try{if(n[e]===t)return e}catch(n){}return-1}var i=Object.defineProperty,a=Date.now()%1e9,u=function(){function n(){if(function(t,e){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this),a+=1,this.name="__weakmap_"+(1e9*Math.random()>>>0)+"__"+a,function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var n=new WeakMap,t={};return Object.freeze(t),n.set(t,"__testvalue__"),"__testvalue__"===n.get(t)}catch(n){return!1}}())try{this.weakmap=new WeakMap}catch(n){}this.keys=[],this.values=[]}return n.prototype._cleanupClosedWindows=function(){for(var n=this.weakmap,t=this.keys,e=0;e<t.length;e++){var o=t[e];if(Object(r.isWindow)(o)&&Object(r.isWindowClosed)(o)){if(n)try{n.delete(o)}catch(n){}t.splice(e,1),this.values.splice(e,1),e-=1}}},n.prototype.isSafeToReadWrite=function(n){if(Object(r.isWindow)(n))return!1;try{n&&n.self,n&&n[this.name]}catch(n){return!1}return!0},n.prototype.set=function(n,t){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{e.set(n,t)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var r=this.name,a=n[r];a&&a[0]===n?a[1]=t:i(n,r,{value:[n,t],writable:!0})}else{this._cleanupClosedWindows();var u=this.keys,c=this.values,s=o(u,n);-1===s?(u.push(n),c.push(t)):c[s]=t}},n.prototype.get=function(n){if(!n)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{if(t.has(n))return t.get(n)}catch(n){delete this.weakmap}if(!this.isSafeToReadWrite(n)){this._cleanupClosedWindows();var e=o(this.keys,n);if(-1===e)return;return this.values[e]}var r=n[this.name];if(r&&r[0]===n)return r[1]},n.prototype.delete=function(n){if(!n)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{t.delete(n)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var e=n[this.name];e&&e[0]===n&&(e[0]=e[1]=void 0)}else{this._cleanupClosedWindows();var r=this.keys,i=o(r,n);-1!==i&&(r.splice(i,1),this.values.splice(i,1))}},n.prototype.has=function(n){if(!n)throw new Error("WeakMap expected key");var t=this.weakmap;if(t)try{if(t.has(n))return!0}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var e=n[this.name];return!(!e||e[0]!==n)}return this._cleanupClosedWindows(),-1!==o(this.keys,n)},n.prototype.getOrSet=function(n,t){if(this.has(n))return this.get(n);var e=t();return this.set(n,e),e},n}();e.d(t,"a",function(){return u})},function(n,t,e){"use strict";e.d(t,"a",function(){return r}),e.d(t,"b",function(){return o}),e.d(t,"c",function(){return i});var r={MOCK:"mock:",FILE:"file:",ABOUT:"about:"},o="*",i={IFRAME:"iframe",POPUP:"popup"}},function(n,t,e){"use strict";t.a=function(){return!!(window.navigator.mockUserAgent||window.navigator.userAgent).match(/Android|webOS|iPhone|iPad|iPod|bada|Symbian|Palm|CriOS|BlackBerry|IEMobile|WindowsMobile|Opera Mini/i)}},function(n,t,e){"use strict";e(1),e(0),e(4);var r=e(3);e(6),t.b=function n(){return Object(r.e)(n,function(){try{if("undefined"==typeof window)return!1;if(window.localStorage){var n=Math.random().toString();window.localStorage.setItem("__test__localStorage__",n);var t=window.localStorage.getItem("__test__localStorage__");if(window.localStorage.removeItem("__test__localStorage__"),n===t)return!0}}catch(n){}return!1})},t.a=function(n,t,e){return n.addEventListener(t,e),{cancel:function(){n.removeEventListener(t,e)}}},"function"==typeof Symbol&&Symbol.iterator,Object.assign,Object.create(Error.prototype)},function(n,t,e){"use strict";t.a=function n(t){var e=t.name,i=t.version,a=void 0===i?"latest":i,u=t.lifetime,c=void 0===u?3e5:u;return Object(r.e)(n,function(){var n="__"+e+"_"+a+"_storage__",t=void 0;function i(e){var i=Object(o.b)(),a=void 0;if(t&&(a=t),!a&&i){var u=window.localStorage.getItem(n);u&&(a=JSON.parse(u))}a||(a=Object(r.c)()[n]),a||(a={id:Object(r.q)()}),a.id||(a.id=Object(r.q)()),t=a;var c=e(a);return i?window.localStorage.setItem(n,JSON.stringify(a)):Object(r.c)()[n]=a,t=null,c}function u(n){return i(function(t){var e=t.__session__,o=Date.now();return e&&o-e.created>c&&(e=null),e||(e={guid:Object(r.q)(),created:o}),t.__session__=e,n(e)})}return{getState:i,getID:function(){return i(function(n){return n.id})},getSessionState:function(n){return u(function(t){return t.state=t.state||{},n(t.state)})},getSessionID:function(){return u(function(n){return n.guid})}}},[{name:e,version:a,lifetime:c}])};var r=e(3),o=e(7)},function(n,t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};e.d(r,"markWindowKnown",function(){return j}),e.d(r,"serializeMessage",function(){return Y}),e.d(r,"deserializeMessage",function(){return Q}),e.d(r,"ProxyWindow",function(){return F}),e.d(r,"cleanUpWindow",function(){return Dn}),e.d(r,"Promise",function(){return a.a}),e.d(r,"bridge",function(){return In}),e.d(r,"parent",function(){return jn}),e.d(r,"send",function(){return vn}),e.d(r,"requestPromises",function(){return pn}),e.d(r,"request",function(){return mn}),e.d(r,"sendToParent",function(){return yn}),e.d(r,"client",function(){return gn}),e.d(r,"on",function(){return bn}),e.d(r,"listen",function(){return En}),e.d(r,"once",function(){return _n}),e.d(r,"listener",function(){return Wn}),e.d(r,"CONFIG",function(){return w}),e.d(r,"disable",function(){return Sn});var o,i=e(0),a=e(1),u=e(2),c={REQUEST:"postrobot_message_request",RESPONSE:"postrobot_message_response",ACK:"postrobot_message_ack"},s={METHOD:"postrobot_method",HELLO:"postrobot_hello",OPEN_TUNNEL:"postrobot_open_tunnel"},f={POSTROBOT:"__postRobot__"},d="*",l={CROSS_DOMAIN_ZALGO_PROMISE:"cross_domain_zalgo_promise",CROSS_DOMAIN_FUNCTION:"cross_domain_function",CROSS_DOMAIN_WINDOW:"cross_domain_window"},w={BRIDGE_TIMEOUT:5e3,CHILD_WINDOW_TIMEOUT:5e3,ACK_TIMEOUT:2e3,ACK_TIMEOUT_KNOWN:1e4,RES_TIMEOUT:-1,ALLOWED_POST_MESSAGE_METHODS:(o={},o.postrobot_post_message=!0,o.postrobot_bridge=!0,o.postrobot_global=!0,o)},h=e(4),p=window[f.POSTROBOT]=window[f.POSTROBOT]||{},m=p.windowStore=p.windowStore||new h.a,v=function(){return{}};function y(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v;function e(n){return m.getOrSet(n,t)}return{has:function(t){return e(t).hasOwnProperty(n)},get:function(t,r){var o=e(t);return o.hasOwnProperty(n)?o[n]:r},set:function(t,r){return e(t)[n]=r,r},del:function(t){delete e(t)[n]},getOrSet:function(t,r){var o=e(t);if(o.hasOwnProperty(n))return o[n];var i=r();return o[n]=i,i}}}function g(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:v,e=Object(u.getOrSet)(p,n,t);return{has:function(n){return e.hasOwnProperty(n)},get:function(n,t){return e.hasOwnProperty(n)?e[n]:t},set:function(n,t){return e[n]=t,t},del:function(n){delete e[n]},getOrSet:function(n,t){if(e.hasOwnProperty(n))return e[n];var r=t();return e[n]=r,r},reset:function(){e=t()},keys:function(){return Object.keys(e)}}}p.instanceID=p.instanceID||Object(u.uniqueID)();var O=y("helloPromises");function E(n){return O.getOrSet(n,function(){return new a.a})}var b=Object(u.once)(function(){p.on(s.HELLO,{domain:d},function(n){var t=n.source,e=n.origin;return E(t).resolve({win:t,domain:e}),{instanceID:p.instanceID}})});function _(n){return p.send(n,s.HELLO,{instanceID:p.instanceID},{domain:d,timeout:-1}).then(function(t){var e=t.origin,r=t.data.instanceID;return E(n).resolve({win:n,domain:e}),{win:n,domain:e,instanceID:r}})}var W=Object(u.weakMapMemoizePromise)(function(n){return _(n).then(function(n){return n.instanceID})}),S=y("knownWindows");function j(n){S.set(n,!0)}var D,I={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"},P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function A(n){return"object"===(void 0===n?"undefined":P(n))&&null!==n&&"string"==typeof n.__type__}function T(n){return void 0===n?I.UNDEFINED:null===n?I.NULL:Array.isArray(n)?I.ARRAY:"function"==typeof n?I.FUNCTION:"object"===(void 0===n?"undefined":P(n))?n instanceof Error?I.ERROR:"function"==typeof n.then?I.PROMISE:"[object RegExp]"===Object.prototype.toString.call(n)?I.REGEX:"[object Date]"===Object.prototype.toString.call(n)?I.DATE:I.OBJECT:"string"==typeof n?I.STRING:"number"==typeof n?I.NUMBER:"boolean"==typeof n?I.BOOLEAN:void 0}function N(n,t){return{__type__:n,__val__:t}}var R,C=((D={})[I.FUNCTION]=function(){},D[I.ERROR]=function(n){var t=n.message,e=n.stack,r=n.code;return N(I.ERROR,{message:t,stack:e,code:r})},D[I.PROMISE]=function(){},D[I.REGEX]=function(n){return N(I.REGEX,n.source)},D[I.DATE]=function(n){return N(I.DATE,n.toJSON())},D[I.ARRAY]=function(n){return n},D[I.OBJECT]=function(n){return n},D[I.STRING]=function(n){return n},D[I.NUMBER]=function(n){return n},D[I.BOOLEAN]=function(n){return n},D[I.NULL]=function(n){return n},D),x={},M=((R={})[I.FUNCTION]=function(){throw new Error("Function serialization is not implemented; nothing to deserialize")},R[I.ERROR]=function(n){var t=n.message,e=n.stack,r=n.code,o=new Error(t);return o.code=r,o.stack=e+"\n\n"+o.stack,o},R[I.PROMISE]=function(){throw new Error("Promise serialization is not implemented; nothing to deserialize")},R[I.REGEX]=function(n){return new RegExp(n)},R[I.DATE]=function(n){return new Date(n)},R[I.ARRAY]=function(n){return n},R[I.OBJECT]=function(n){return n},R[I.STRING]=function(n){return n},R[I.NUMBER]=function(n){return n},R[I.BOOLEAN]=function(n){return n},R[I.NULL]=function(n){return n},R),k={},U=y("winToProxyWindow"),L=g("idToProxyWindow");function z(){for(var n=0,t=L.keys(),e=null==t?0:t.length;n<e;n++){var r=t[n];L.get(r).shouldClean()&&L.del(r)}}var F=function(){function n(t,e){!function(t,e){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this),this.isProxyWindow=!0,this.serializedWindow=t,this.actualWindowPromise=new a.a,e&&this.setWindow(e),this.serializedWindow.getInstanceID=Object(u.memoizePromise)(this.serializedWindow.getInstanceID)}return n.prototype.getType=function(){return this.serializedWindow.type},n.prototype.isPopup=function(){return this.getType()===i.WINDOW_TYPE.POPUP},n.prototype.isIframe=function(){return this.getType()===i.WINDOW_TYPE.IFRAME},n.prototype.setLocation=function(n){var t=this;return a.a.try(function(){if(!t.actualWindow)return t.serializedWindow.setLocation(n);t.actualWindow.location=n}).then(function(){return t})},n.prototype.setName=function(n){var t=this;return a.a.try(function(){if(!t.actualWindow)return t.serializedWindow.setName(n);if(!Object(i.isSameDomain)(t.actualWindow))throw new Error("Can not set name for window on different domain");t.actualWindow.name=n,t.actualWindow.frameElement&&t.actualWindow.frameElement.setAttribute("name",n)}).then(function(){return t})},n.prototype.close=function(){var n=this;return a.a.try(function(){if(!n.actualWindow)return n.serializedWindow.close();n.actualWindow.close()}).then(function(){return n})},n.prototype.focus=function(){var n=this;return a.a.try(function(){return n.actualWindow&&n.actualWindow.focus(),n.serializedWindow.focus()}).then(function(){return n})},n.prototype.isClosed=function(){var n=this;return a.a.try(function(){return n.actualWindow?Object(i.isWindowClosed)(n.actualWindow):n.serializedWindow.isClosed()})},n.prototype.getWindow=function(){return this.actualWindow},n.prototype.setWindow=function(n){this.actualWindow=n,this.actualWindowPromise.resolve(n)},n.prototype.awaitWindow=function(){return this.actualWindowPromise},n.prototype.matchWindow=function(n){var t=this;return a.a.try(function(){return t.actualWindow?n===t.actualWindow:a.a.all([t.getInstanceID(),W(n)]).then(function(e){var r=e[0]===e[1];return r&&t.setWindow(n),r})})},n.prototype.unwrap=function(){return this.actualWindow||this},n.prototype.getInstanceID=function(){return this.actualWindow?W(this.actualWindow):this.serializedWindow.getInstanceID()},n.prototype.serialize=function(){return this.serializedWindow},n.prototype.shouldClean=function(){return this.actualWindow&&Object(i.isWindowClosed)(this.actualWindow)},n.unwrap=function(t){return n.isProxyWindow(t)?t.unwrap():t},n.serialize=function(t){return z(),n.toProxyWindow(t).serialize()},n.deserialize=function(t){return z(),L.getOrSet(t.id,function(){return new n(t)})},n.isProxyWindow=function(n){return Boolean(n&&!Object(i.isWindow)(n)&&n.isProxyWindow)},n.toProxyWindow=function(t){return z(),n.isProxyWindow(t)?t:U.getOrSet(t,function(){var e=Object(u.uniqueID)();return L.set(e,new n({id:e,type:Object(i.getOpener)(t)?i.WINDOW_TYPE.POPUP:i.WINDOW_TYPE.IFRAME,getInstanceID:function(){return W(t)},close:function(){return a.a.try(function(){t.close()})},focus:function(){return a.a.try(function(){t.focus()})},isClosed:function(){return a.a.try(function(){return Object(i.isWindowClosed)(t)})},setLocation:function(n){return a.a.try(function(){if(Object(i.isSameDomain)(t))try{if(t.location&&"function"==typeof t.location.replace)return void t.location.replace(n)}catch(n){}t.location=n})},setName:function(n){return a.a.try(function(){t.name=n})}},t))})},n}(),B=y("methodStore"),H=g("proxyWindowMethods");function q(n,t,e,r,o){F.isProxyWindow(r)?H.set(n,{val:t,name:e,domain:o,source:r}):(H.del(n),B.getOrSet(r,function(){return{}})[n]={domain:o,name:e,val:t,source:r})}function G(n,t){return B.getOrSet(n,function(){return{}})[t]||H.get(t)}p.listeningForFunctions=p.listeningForFunctions||!1;var J=Object(u.once)(function(){p.listeningForFunctions||(p.listeningForFunctions=!0,p.on(s.METHOD,{origin:d},function(n){var t=n.source,e=n.origin,r=n.data,o=r.id,c=r.name;return a.a.try(function(){var n=G(t,o);if(!n)throw new Error("Could not find method '"+r.name+"' with id: "+r.id+" in "+Object(i.getDomain)(window));var s=n.source,f=n.domain,d=n.val;return a.a.try(function(){if(!Object(i.matchDomain)(f,e))throw new Error("Method '"+r.name+"' domain "+JSON.stringify(Object(u.isRegex)(n.domain)?n.domain.source:n.domain)+" does not match origin "+e+" in "+Object(i.getDomain)(window));if(F.isProxyWindow(s))return s.matchWindow(t).then(function(n){if(!n)throw new Error("Method call '"+r.name+"' failed - proxy window does not match source in "+Object(i.getDomain)(window))})}).then(function(){return d.apply({source:t,origin:e},r.args)},function(n){return a.a.try(function(){if(d.onError)return d.onError(n)}).then(function(){throw n})}).then(function(n){return{result:n,id:o,name:c}})})}))});function K(n,t,e,r){J();var o=e.__id__||Object(u.uniqueID)();n=F.unwrap(n);var i=e.__name__||e.name||r;return F.isProxyWindow(n)?(q(o,e,i,n,t),n.awaitWindow().then(function(n){q(o,e,i,n,t)})):q(o,e,i,n,t),N(l.CROSS_DOMAIN_FUNCTION,{id:o,name:i})}function Y(n,t,e){var r;return function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:x,e=JSON.stringify(n,function(n){var e=this[n];if(A(this))return e;var r=T(e);if(!r)return e;var o=t[r]||C[r];return o?o(e,n):e});return void 0===e?I.UNDEFINED:e}(e,((r={})[I.PROMISE]=function(e,r){return function(n,t,e,r){return N(l.CROSS_DOMAIN_ZALGO_PROMISE,{then:K(n,t,function(n,t){return e.then(n,t)},r)})}(n,t,e,r)},r[I.FUNCTION]=function(e,r){return K(n,t,e,r)},r[I.OBJECT]=function(n){return Object(i.isWindow)(n)||F.isProxyWindow(n)?(t=n,N(l.CROSS_DOMAIN_WINDOW,F.serialize(t))):n;var t},r))}function Q(n,t,e){var r;return function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:k;if(n!==I.UNDEFINED)return JSON.parse(n,function(n,e){if(A(this))return e;var r=void 0,o=void 0;if(A(e)?(r=e.__type__,o=e.__val__):(r=T(e),o=e),!r)return o;var i=t[r]||M[r];return i?i(o,n):o})}(e,((r={})[l.CROSS_DOMAIN_ZALGO_PROMISE]=function(n){return t=n.then,new a.a(t);var t},r[l.CROSS_DOMAIN_FUNCTION]=function(e){return function(n,t,e){var r=e.id,o=e.name,a=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};function a(){var u=arguments;return F.toProxyWindow(n).awaitWindow().then(function(n){var c=G(n,r);return c&&c.val!==a?c.val.apply({source:window,origin:Object(i.getDomain)()},u):p.send(n,s.METHOD,{id:r,name:o,args:Array.prototype.slice.call(u)},{domain:t,fireAndForget:e.fireAndForget}).then(function(n){if(!e.fireAndForget)return n.data.result})}).catch(function(n){throw n})}return a.__name__=o,a.__origin__=t,a.__source__=n,a.__id__=r,a.origin=t,a},u=a();return u.fireAndForget=a({fireAndForget:!0}),u}(n,t,e)},r[l.CROSS_DOMAIN_WINDOW]=function(n){return t=n,F.deserialize(t);var t},r))}var X={postrobot_post_message:function(n,t,e){(Array.isArray(e)?e:"string"==typeof e?[e]:[d]).map(function(t){if(0===t.indexOf("mock:")){if("file:"===window.location.protocol)return d;if(!Object(i.isActuallySameDomain)(n))throw new Error("Attempting to send messsage to mock domain "+t+", but window is actually cross-domain");return Object(i.getActualDomain)(n)}return 0===t.indexOf("file:")?d:t}).forEach(function(e){return n.postMessage(t,e)})}},Z=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n};function V(n,t,e){return a.a.try(function(){var r;if(Object(i.isWindowClosed)(n))throw new Error("Window is closed");var o=Y(n,t,((r={})[f.POSTROBOT]=Z({id:Object(u.uniqueID)()},e),r)),c=[];return a.a.map(Object.keys(X),function(e){return a.a.try(function(){if(!w.ALLOWED_POST_MESSAGE_METHODS[e])throw new Error("Strategy disallowed: "+e);return X[e](n,o,t)}).then(function(){return c.push(e+": success"),!0},function(n){return c.push(e+": "+Object(u.stringifyError)(n)+"\n"),!1})}).then(function(n){var t=n.some(Boolean),r=e.type+" "+e.name+" "+(t?"success":"error")+":\n - "+c.join("\n - ")+"\n";if(!t)throw new Error(r)})})}var $=g("responseListeners"),nn=y("requestListeners"),tn=g("erroredResponseListeners");p.WINDOW_WILDCARD=p.WINDOW_WILDCARD||new function(){};var en,rn="__domain_regex__";function on(n){return $.get(n)}function an(n){$.del(n)}function un(n){return tn.has(n)}function cn(n){var t=n.name,e=n.win,r=n.domain;if(e===d&&(e=null),r===d&&(r=null),!t)throw new Error("Name required to get request listener");for(var o=0,a=[e,p.WINDOW_WILDCARD],u=null==a?0:a.length;o<u;o++){var c=a[o];if(c){var s=nn.get(c);if(s){var f=s[t];if(f){if(r&&"string"==typeof r){if(f[r])return f[r];if(f[rn])for(var l=0,w=f[rn],h=null==w?0:w.length;l<h;l++){var m=w[l],v=m.regex,y=m.listener;if(Object(i.matchDomain)(v,r))return y}}if(f[d])return f[d]}}}}}var sn=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},fn=((en={})[c.REQUEST]=function(n,t,e){var r=cn({name:e.name,win:n,domain:t});function o(r,o){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e.fireAndForget||Object(i.isWindowClosed)(n)?a.a.resolve():V(n,t,sn({type:r,ack:o,hash:e.hash,name:e.name},u))}return e.name===s.METHOD&&e.data&&"string"==typeof e.data.name?e.data.name:e.name,a.a.all([o(c.ACK),a.a.try(function(){if(!r)throw new Error("No handler found for post message: "+e.name+" from "+t+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!Object(i.matchDomain)(r.domain,t))throw new Error("Request origin "+t+" does not match domain "+r.domain.toString());var o=e.data;return r.handler({source:n,origin:t,data:o})}).then(function(n){return o(c.RESPONSE,"success",{data:n})},function(n){return o(c.RESPONSE,"error",{error:n})})]).then(u.noop).catch(function(n){if(r&&r.handleError)return r.handleError(n);throw n})},en[c.ACK]=function(n,t,e){if(!un(e.hash)){var r=on(e.hash);if(!r)throw new Error("No handler found for post message ack for message: "+e.name+" from "+t+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!Object(i.matchDomain)(r.domain,t))throw new Error("Ack origin "+t+" does not match domain "+r.domain.toString());r.ack=!0}},en[c.RESPONSE]=function(n,t,e){if(!un(e.hash)){var r=on(e.hash);if(!r)throw new Error("No handler found for post message response for message: "+e.name+" from "+t+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!Object(i.matchDomain)(r.domain,t))throw new Error("Response origin "+t+" does not match domain "+Object(i.stringifyDomainPattern)(r.domain));if(an(e.hash),"error"===e.ack)return r.respond(e.error,null);if("success"===e.ack){var o=e.data;return r.respond(null,{source:n,origin:t,data:o})}}},en),dn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},ln=g("receivedMessages");function wn(n){if(!window||window.closed)throw new Error("Message recieved in closed window");try{if(!n.source)return}catch(n){return}var t=n.source,e=n.origin,r=function(n,t,e){var r=void 0;try{r=Q(t,e,n)}catch(n){return}if(r&&"object"===(void 0===r?"undefined":dn(r))&&null!==r&&(r=r[f.POSTROBOT])&&"object"===(void 0===r?"undefined":dn(r))&&null!==r&&r.type&&"string"==typeof r.type&&fn[r.type])return r}(n.data,t,e);r&&(j(t),ln.has(r.id)||(ln.set(r.id,!0),Object(i.isWindowClosed)(t)&&!r.fireAndForget||fn[r.type](t,e,r)))}function hn(n){try{Object(u.noop)(n.source)}catch(n){return}var t={source:n.source||n.sourceElement,origin:n.origin||n.originalEvent&&n.originalEvent.origin,data:n.data};if(t.source){if(!t.origin)throw new Error("Post message did not have origin domain");wn(t)}}p.receiveMessage=wn;var pn=y("requestPromises");function mn(n){return a.a.try(function(){if(!n.name)throw new Error("Expected options.name");var t=n.name,e=void 0,r=void 0;if("string"==typeof n.window){var o=document.getElementById(n.window);if(!o)throw new Error("Expected options.window "+Object.prototype.toString.call(n.window)+" to be a valid element id");if("iframe"!==o.tagName.toLowerCase())throw new Error("Expected options.window "+Object.prototype.toString.call(n.window)+" to be an iframe");if(!o.contentWindow)throw new Error("Iframe must have contentWindow. Make sure it has a src attribute and is in the DOM.");e=o.contentWindow}else if(n.window instanceof HTMLIFrameElement){if("iframe"!==n.window.tagName.toLowerCase())throw new Error("Expected options.window "+Object.prototype.toString.call(n.window)+" to be an iframe");if(n.window&&!n.window.contentWindow)throw new Error("Iframe must have contentWindow. Make sure it has a src attribute and is in the DOM.");n.window&&n.window.contentWindow&&(e=n.window.contentWindow)}else e=n.window;if(!e)throw new Error("Expected options.window to be a window object, iframe, or iframe element id.");var f=e;r=n.domain||d;var l=n.name+"_"+Object(u.uniqueID)();if(Object(i.isWindowClosed)(f))throw new Error("Target window is closed");var h=!1,p=pn.getOrSet(f,function(){return[]}),m=a.a.try(function(){if(Object(i.isAncestor)(window,f))return function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Window",r=E(n);return-1!==t&&(r=r.timeout(t,new Error(e+" did not load after "+t+"ms"))),r}(f,n.timeout||w.CHILD_WINDOW_TIMEOUT)}).then(function(){var n=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).domain;if(Object(u.isRegex)(r)&&!n)return _(f)}).then(function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).domain;if(Object(u.isRegex)(r)){if(!Object(i.matchDomain)(r,e))throw new Error("Remote window domain "+e+" does not match regex: "+r.toString());r=e}if("string"!=typeof r&&!Array.isArray(r))throw new TypeError("Expected domain to be a string or array");var o=r;return t===s.METHOD&&n.data&&"string"==typeof n.data.name&&n.data.name,new a.a(function(e,r){var a=void 0;if(n.fireAndForget||function(n,t){$.set(n,t)}(l,a={name:t,window:f,domain:o,respond:function(n,t){n||(h=!0,p.splice(p.indexOf(m,1))),n?r(n):e(t)}}),V(f,o,{type:c.REQUEST,hash:l,name:t,data:n.data,fireAndForget:Boolean(n.fireAndForget)}).catch(r),n.fireAndForget)return e();var u=function(n){return S.get(n,!1)}(f)?w.ACK_TIMEOUT_KNOWN:w.ACK_TIMEOUT,s=n.timeout||w.RES_TIMEOUT,d=u,v=s,y=100;setTimeout(function n(){if(!h){if(Object(i.isWindowClosed)(f))return a.ack?r(new Error("Window closed for "+t+" before response")):r(new Error("Window closed for "+t+" before ack"));if(d=Math.max(d-y,0),-1!==v&&(v=Math.max(v-y,0)),a.ack){if(-1===v)return;y=Math.min(v,2e3)}else{if(0===d)return r(new Error("No ack for postMessage "+t+" in "+Object(i.getDomain)()+" in "+u+"ms"));if(0===v)return r(new Error("No response for postMessage "+t+" in "+Object(i.getDomain)()+" in "+s+"ms"))}setTimeout(n,y)}},y)})});return m.catch(function(){!function(n){tn.set(n,!0)}(l),an(l)}),p.push(m),m})}function vn(n,t,e,r){return(r=r||{}).window=n,r.name=t,r.data=e,mn(r)}function yn(n,t,e){var r=Object(i.getAncestor)();return r?vn(r,n,t,e):new a.a(function(n,t){return t(new Error("Window does not have a parent"))})}function gn(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!n.window)throw new Error("Expected options.window");var t=n.window;return{send:function(e,r){return vn(t,e,r,n)}}}p.send=vn;var On="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function En(n){if(!n.name)throw new Error("Expected options.name");if(!n.handler)throw new Error("Expected options.handler");var t=n.name,e=n.window,r=n.domain,o={handler:n.handler,handleError:n.errorHandler||function(n){throw n},window:e,domain:r||d,name:t},a=function n(t,e){var r=t.name,o=t.win,i=t.domain;if(!r||"string"!=typeof r)throw new Error("Name required to add request listener");if(Array.isArray(o)){for(var a=[],c=0,s=o,f=null==s?0:s.length;c<f;c++){var l=s[c];a.push(n({name:r,domain:i,win:l},e))}return{cancel:function(){for(var n=0,t=null==a?0:a.length;n<t;n++)a[n].cancel()}}}if(Array.isArray(i)){for(var w=[],h=0,m=i,v=null==m?0:m.length;h<v;h++){var y=m[h];w.push(n({name:r,win:o,domain:y},e))}return{cancel:function(){for(var n=0,t=null==w?0:w.length;n<t;n++)w[n].cancel()}}}var g=cn({name:r,win:o,domain:i});if(o&&o!==d||(o=p.WINDOW_WILDCARD),i=i||d,g)throw o&&i?new Error("Request listener already exists for "+r+" on domain "+i.toString()+" for "+(o===p.WINDOW_WILDCARD?"wildcard":"specified")+" window"):o?new Error("Request listener already exists for "+r+" for "+(o===p.WINDOW_WILDCARD?"wildcard":"specified")+" window"):i?new Error("Request listener already exists for "+r+" on domain "+i.toString()):new Error("Request listener already exists for "+r);var O=nn.getOrSet(o,function(){return{}}),E=Object(u.getOrSet)(O,r,function(){return{}}),b=i.toString(),_=void 0,W=void 0;return Object(u.isRegex)(i)?(_=Object(u.getOrSet)(E,rn,function(){return[]}),W={regex:i,listener:e},_.push(W)):E[b]=e,{cancel:function(){delete E[b],W&&(_.splice(_.indexOf(W,1)),_.length||delete E[rn]),Object.keys(E).length||delete O[r],o&&!Object.keys(O).length&&nn.del(o)}}}({name:t,win:e,domain:r},o);if(n.once){var c=o.handler;o.handler=Object(u.once)(function(){return a.cancel(),c.apply(this,arguments)})}if(o.window&&n.errorOnClose)var s=Object(u.safeInterval)(function(){e&&"object"===(void 0===e?"undefined":On(e))&&Object(i.isWindowClosed)(e)&&(s.cancel(),o.handleError(new Error("Post message target window is closed")))},50);return{cancel:function(){a.cancel()}}}function bn(n,t,e){return"function"==typeof t&&(e=t,t={}),(t=t||{}).name=n,t.handler=e||t.handler,En(t)}function _n(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=arguments[2];"function"==typeof t&&(e=t,t={}),t=t||{},e=e||t.handler;var r=t.errorHandler,o=new a.a(function(o,i){(t=t||{}).name=n,t.once=!0,t.handler=function(n){if(o(n),e)return e(n)},t.errorHandler=function(n){if(i(n),r)return r(n)}}),i=En(t);return o.cancel=i.cancel,o}function Wn(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{on:function(t,e){return bn(t,n,e)}}}function Sn(){delete window[f.POSTROBOT],window.removeEventListener("message",hn)}p.on=bn;var jn=Object(i.getAncestor)();function Dn(n){for(var t=0,e=pn.get(n,[]),r=null==e?0:e.length;t<r;t++)e[t].reject(new Error("Window cleaned up before response")).catch(u.noop)}var In=null;p.initialized||(p.initialized=!0,Object(u.addEventListener)(window,"message",hn),In&&In.openTunnelToOpener(),function(){b();var n=Object(i.getAncestor)();n&&_(n).catch(u.noop)}()),e.d(t,"markWindowKnown",function(){return j}),e.d(t,"serializeMessage",function(){return Y}),e.d(t,"deserializeMessage",function(){return Q}),e.d(t,"ProxyWindow",function(){return F}),e.d(t,"cleanUpWindow",function(){return Dn}),e.d(t,"Promise",function(){return a.a}),e.d(t,"bridge",function(){return In}),e.d(t,"parent",function(){return jn}),e.d(t,"send",function(){return vn}),e.d(t,"requestPromises",function(){return pn}),e.d(t,"request",function(){return mn}),e.d(t,"sendToParent",function(){return yn}),e.d(t,"client",function(){return gn}),e.d(t,"on",function(){return bn}),e.d(t,"listen",function(){return En}),e.d(t,"once",function(){return _n}),e.d(t,"listener",function(){return Wn}),e.d(t,"CONFIG",function(){return w}),e.d(t,"disable",function(){return Sn}),t.default=r},function(n,t,e){"use strict";function r(n){return"[object RegExp]"===Object.prototype.toString.call(n)}var o=e(5);t.d=c,t.a=f,t.c=d,t.f=l,t.h=w,t.j=function(n){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];try{if(n===window)return!1}catch(n){return!0}try{if(!n)return!0}catch(n){return!0}try{if(n.closed)return!0}catch(n){return!n||n.message!==i}if(t&&w(n))try{if(n.mockclosed)return!0}catch(n){}try{if(!n.parent||!n.top)return!0}catch(n){}var e=function(n,t){for(var e=0;e<n.length;e++)try{if(n[e]===t)return e}catch(n){}return-1}(m,n);if(-1!==e){var r=v[e];if(r&&function(n){if(!n.contentWindow)return!0;if(!n.parentNode)return!0;var t=n.ownerDocument;return!(!t||!t.documentElement||t.documentElement.contains(n))}(r))return!0}return!1},t.k=function(n){if(function(){for(var n=0;n<m.length;n++){var t=!1;try{t=m[n].closed}catch(n){}t&&(v.splice(n,1),m.splice(n,1))}}(),n&&n.contentWindow)try{m.push(n.contentWindow),v.push(n)}catch(n){}},t.e=function(n){return(n=n||window).navigator.mockUserAgent||n.navigator.userAgent},t.b=y,t.g=function(n,t){var e=y(t);if(e)return e===n;if(t===n)return!1;if(function(n){if(n){try{if(n.top)return n.top}catch(n){}if(u(n)===n)return n;try{if(h(window,n)&&window.top)return window.top}catch(n){}try{if(h(n,window)&&window.top)return window.top}catch(n){}for(var t=0,e=function n(t){for(var e=[],r=0,o=p(t),i=null==o?0:o.length;r<i;r++){var a=o[r];e.push(a);for(var u=0,c=n(a),s=null==c?0:c.length;u<s;u++){var f=c[u];e.push(f)}}return e}(n),r=null==e?0:e.length;t<r;t++){var o=e[t];try{if(o.top)return o.top}catch(n){}if(u(o)===o)return o}}}(t)===t)return!1;for(var r=0,o=p(n),i=null==o?0:o.length;r<i;r++)if(o[r]===t)return!0;return!1},t.l=function n(t,e){if("string"==typeof t){if("string"==typeof e)return t===o.b||e===t;if(r(e))return!1;if(Array.isArray(e))return!1}return r(t)?r(e)?t.toString()===e.toString():!Array.isArray(e)&&Boolean(e.match(t)):!!Array.isArray(t)&&(Array.isArray(e)?JSON.stringify(t)===JSON.stringify(e):!r(e)&&t.some(function(t){return n(t,e)}))},t.m=function(n){return Array.isArray(n)?"("+n.join(" | ")+")":r(n)?"RegExp("+n.toString():n.toString()},t.i=function(n){try{if(n===window)return!0}catch(n){if(n&&n.message===i)return!0}try{if("[object Window]"===Object.prototype.toString.call(n))return!0}catch(n){if(n&&n.message===i)return!0}try{if(window.Window&&n instanceof window.Window)return!0}catch(n){if(n&&n.message===i)return!0}try{if(n&&n.self===n)return!0}catch(n){if(n&&n.message===i)return!0}try{if(n&&n.parent===n)return!0}catch(n){if(n&&n.message===i)return!0}try{if(n&&n.top===n)return!0}catch(n){if(n&&n.message===i)return!0}try{n&&n.__cross_domain_utils_window_check__}catch(n){return!0}return!1};var i="Call was rejected by callee.\r\n";function a(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:window).location.protocol===o.a.ABOUT}function u(n){if(n)try{if(n.parent&&n.parent!==n)return n.parent}catch(n){}}function c(n){if(n&&!u(n))try{return n.opener}catch(n){}}function s(n){try{return n&&n.location&&n.location.href,!0}catch(n){}return!1}function f(n){var t=(n=n||window).location;if(!t)throw new Error("Can not read window location");var e=t.protocol;if(!e)throw new Error("Can not read window protocol");if(e===o.a.FILE)return o.a.FILE+"//";if(e===o.a.ABOUT){var r=u(n);return r&&s(r)?f(r):o.a.ABOUT+"//"}var i=t.host;if(!i)throw new Error("Can not read window host");return e+"//"+i}function d(n){var t=f(n=n||window);return t&&n.mockDomain&&0===n.mockDomain.indexOf(o.a.MOCK)?n.mockDomain:t}function l(n){try{if(n===window)return!0}catch(n){}try{var t=Object.getOwnPropertyDescriptor(n,"location");if(t&&!1===t.enumerable)return!1}catch(n){}try{if(a(n)&&s(n))return!0}catch(n){}try{if(f(n)===f(window))return!0}catch(n){}return!1}function w(n){if(!l(n))return!1;try{if(n===window)return!0;if(a(n)&&s(n))return!0;if(d(window)===d(n))return!0}catch(n){}return!1}function h(n,t){if(!n||!t)return!1;var e=u(t);return e?e===n:-1!==function(n){var t=[];try{for(;n.parent!==n;)t.push(n.parent),n=n.parent}catch(n){}return t}(t).indexOf(n)}function p(n){var t=[],e=void 0;try{e=n.frames}catch(t){e=n}var r=void 0;try{r=e.length}catch(n){}if(0===r)return t;if(r){for(var o=0;o<r;o++){var i=void 0;try{i=e[o]}catch(n){continue}t.push(i)}return t}for(var a=0;a<100;a++){var u=void 0;try{u=e[a]}catch(n){return t}if(!u)return t;t.push(u)}return t}var m=[],v=[];function y(n){return c(n=n||window)||u(n)||void 0}},function(n,t){},function(n,t,e){"use strict";e(3),e(8)},function(n,t,e){"use strict";e(3)},function(n,t,e){"use strict";e(1),e(0)},function(n,t){},function(n,t,e){"use strict";e(3)},function(n,t,e){"use strict"},function(n,t,e){"use strict";e(1),e(3)}])}); | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("postRobot",[],e):"object"==typeof exports?exports.postRobot=e():n.postRobot=e()}("undefined"!=typeof self?self:this,function(){return function(n){var e={};function r(t){if(e[t])return e[t].exports;var o=e[t]={i:t,l:!1,exports:{}};return n[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=n,r.c=e,r.d=function(n,e,t){r.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:t})},r.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},r.t=function(n,e){if(1&e&&(n=r(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)r.d(t,o,function(e){return n[e]}.bind(null,o));return t},r.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(e,"a",e),e},r.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},r.p="",r(r.s=0)}([function(n,e,r){"use strict";r.r(e);var t={};function o(n){return"[object RegExp]"===Object.prototype.toString.call(n)}r.r(t),r.d(t,"WeakMap",function(){return L});var i={MOCK:"mock:",FILE:"file:",ABOUT:"about:"},a="*",u="Call was rejected by callee.\r\n";function c(n){return void 0===n&&(n=window),n.location.protocol===i.ABOUT}function s(n){if(n)try{if(n.parent&&n.parent!==n)return n.parent}catch(n){}}function f(n){if(n&&!s(n))try{return n.opener}catch(n){}}function d(n){try{return n&&n.location&&n.location.href,!0}catch(n){}return!1}function l(n){var e=(n=n||window).location;if(!e)throw new Error("Can not read window location");var r=e.protocol;if(!r)throw new Error("Can not read window protocol");if(r===i.FILE)return i.FILE+"//";if(r===i.ABOUT){var t=s(n);return t&&d(t)?l(t):i.ABOUT+"//"}var o=e.host;if(!o)throw new Error("Can not read window host");return r+"//"+o}function h(n){var e=l(n=n||window);return e&&n.mockDomain&&0===n.mockDomain.indexOf(i.MOCK)?n.mockDomain:e}function w(n){try{if(n===window)return!0}catch(n){}try{var e=Object.getOwnPropertyDescriptor(n,"location");if(e&&!1===e.enumerable)return!1}catch(n){}try{if(c(n)&&d(n))return!0}catch(n){}try{if(l(n)===l(window))return!0}catch(n){}return!1}function p(n){if(!w(n))return!1;try{if(n===window)return!0;if(c(n)&&d(n))return!0;if(h(window)===h(n))return!0}catch(n){}return!1}function v(n,e){if(!n||!e)return!1;var r=s(e);return r?r===n:-1!==function(n){var e=[];try{for(;n.parent!==n;)e.push(n.parent),n=n.parent}catch(n){}return e}(e).indexOf(n)}function m(n){var e,r,t=[];try{e=n.frames}catch(r){e=n}try{r=e.length}catch(n){}if(0===r)return t;if(r){for(var o=0;o<r;o++){var i=void 0;try{i=e[o]}catch(n){continue}t.push(i)}return t}for(var a=0;a<100;a++){var u=void 0;try{u=e[a]}catch(n){return t}if(!u)return t;t.push(u)}return t}var y=[],g=[];function E(n,e){void 0===e&&(e=!0);try{if(n===window)return!1}catch(n){return!0}try{if(!n)return!0}catch(n){return!0}try{if(n.closed)return!0}catch(n){return!n||n.message!==u}if(e&&p(n))try{if(n.mockclosed)return!0}catch(n){}try{if(!n.parent||!n.top)return!0}catch(n){}var r=function(n,e){for(var r=0;r<n.length;r++)try{if(n[r]===e)return r}catch(n){}return-1}(y,n);if(-1!==r){var t=g[r];if(t&&function(n){if(!n.contentWindow)return!0;if(!n.parentNode)return!0;var e=n.ownerDocument;return!(!e||!e.documentElement||e.documentElement.contains(n))}(t))return!0}return!1}function _(n){return f(n=n||window)||s(n)||void 0}function O(n,e){if("string"==typeof n){if("string"==typeof e)return n===a||e===n;if(o(e))return!1;if(Array.isArray(e))return!1}return o(n)?o(e)?n.toString()===e.toString():!Array.isArray(e)&&Boolean(e.match(n)):!!Array.isArray(n)&&(Array.isArray(e)?JSON.stringify(n)===JSON.stringify(e):!o(e)&&n.some(function(n){return O(n,e)}))}function W(n){try{if(n===window)return!0}catch(n){if(n&&n.message===u)return!0}try{if("[object Window]"===Object.prototype.toString.call(n))return!0}catch(n){if(n&&n.message===u)return!0}try{if(window.Window&&n instanceof window.Window)return!0}catch(n){if(n&&n.message===u)return!0}try{if(n&&n.self===n)return!0}catch(n){if(n&&n.message===u)return!0}try{if(n&&n.parent===n)return!0}catch(n){if(n&&n.message===u)return!0}try{if(n&&n.top===n)return!0}catch(n){if(n&&n.message===u)return!0}try{n&&n.__cross_domain_utils_window_check__}catch(n){return!0}return!1}function S(n){try{if(!n)return!1;if("undefined"!=typeof Promise&&n instanceof Promise)return!0;if("undefined"!=typeof window&&window.Window&&n instanceof window.Window)return!1;if("undefined"!=typeof window&&window.constructor&&n instanceof window.constructor)return!1;var e={}.toString;if(e){var r=e.call(n);if("[object Window]"===r||"[object global]"===r||"[object DOMWindow]"===r)return!1}if("function"==typeof n.then)return!0}catch(n){return!1}return!1}var b,R=[],j=[],x=0;function N(){if(!x&&b){var n=b;b=null,n.resolve()}}function A(){x+=1}function I(){x-=1,N()}var P=function(){function n(n){var e=this;if(this.resolved=void 0,this.rejected=void 0,this.errorHandled=void 0,this.value=void 0,this.error=void 0,this.handlers=void 0,this.dispatching=void 0,this.stack=void 0,this.resolved=!1,this.rejected=!1,this.errorHandled=!1,this.handlers=[],n){var r,t,o=!1,i=!1,a=!1;A();try{n(function(n){a?e.resolve(n):(o=!0,r=n)},function(n){a?e.reject(n):(i=!0,t=n)})}catch(n){return I(),void this.reject(n)}I(),a=!0,o?this.resolve(r):i&&this.reject(t)}}var e=n.prototype;return e.resolve=function(n){if(this.resolved||this.rejected)return this;if(S(n))throw new Error("Can not resolve promise with another promise");return this.resolved=!0,this.value=n,this.dispatch(),this},e.reject=function(n){var e=this;if(this.resolved||this.rejected)return this;if(S(n))throw new Error("Can not reject promise with another promise");if(!n){var r=n&&"function"==typeof n.toString?n.toString():Object.prototype.toString.call(n);n=new Error("Expected reject to be called with Error, got "+r)}return this.rejected=!0,this.error=n,this.errorHandled||setTimeout(function(){e.errorHandled||function(n,e){if(-1===R.indexOf(n)){R.push(n),setTimeout(function(){throw n},1);for(var r=0;r<j.length;r++)j[r](n,e)}}(n,e)},1),this.dispatch(),this},e.asyncReject=function(n){return this.errorHandled=!0,this.reject(n),this},e.dispatch=function(){var e=this,r=this.dispatching,t=this.resolved,o=this.rejected,i=this.handlers;if(!r&&(t||o)){this.dispatching=!0,A();for(var a=function(r){var a=i[r],u=a.onSuccess,c=a.onError,s=a.promise,f=void 0;if(t)try{f=u?u(e.value):e.value}catch(n){return s.reject(n),"continue"}else if(o){if(!c)return s.reject(e.error),"continue";try{f=c(e.error)}catch(n){return s.reject(n),"continue"}}f instanceof n&&(f.resolved||f.rejected)?(f.resolved?s.resolve(f.value):s.reject(f.error),f.errorHandled=!0):S(f)?f instanceof n&&(f.resolved||f.rejected)?f.resolved?s.resolve(f.value):s.reject(f.error):f.then(function(n){s.resolve(n)},function(n){s.reject(n)}):s.resolve(f)},u=0;u<i.length;u++)a(u);i.length=0,this.dispatching=!1,I()}},e.then=function(e,r){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.then expected a function for success handler");if(r&&"function"!=typeof r&&!r.call)throw new Error("Promise.then expected a function for error handler");var t=new n;return this.handlers.push({promise:t,onSuccess:e,onError:r}),this.errorHandled=!0,this.dispatch(),t},e.catch=function(n){return this.then(void 0,n)},e.finally=function(e){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.finally expected a function");return this.then(function(r){return n.try(e).then(function(){return r})},function(r){return n.try(e).then(function(){throw r})})},e.timeout=function(n,e){var r=this;if(this.resolved||this.rejected)return this;var t=setTimeout(function(){r.resolved||r.rejected||r.reject(e||new Error("Promise timed out after "+n+"ms"))},n);return this.then(function(n){return clearTimeout(t),n})},e.toPromise=function(){if("undefined"==typeof Promise)throw new TypeError("Could not find Promise");return Promise.resolve(this)},n.resolve=function(e){return e instanceof n?e:S(e)?new n(function(n,r){return e.then(n,r)}):(new n).resolve(e)},n.reject=function(e){return(new n).reject(e)},n.asyncReject=function(e){return(new n).asyncReject(e)},n.all=function(e){var r=new n,t=e.length,o=[];if(!t)return r.resolve(o),r;for(var i=function(i){var a=e[i];if(a instanceof n){if(a.resolved)return o[i]=a.value,t-=1,"continue"}else if(!S(a))return o[i]=a,t-=1,"continue";n.resolve(a).then(function(n){o[i]=n,0==(t-=1)&&r.resolve(o)},function(n){r.reject(n)})},a=0;a<e.length;a++)i(a);return 0===t&&r.resolve(o),r},n.hash=function(e){var r={};return n.all(Object.keys(e).map(function(t){return n.resolve(e[t]).then(function(n){r[t]=n})})).then(function(){return r})},n.map=function(e,r){return n.all(e.map(r))},n.onPossiblyUnhandledException=function(n){return function(n){return j.push(n),{cancel:function(){j.splice(j.indexOf(n),1)}}}(n)},n.try=function(e,r,t){if(e&&"function"!=typeof e&&!e.call)throw new Error("Promise.try expected a function");var o;A();try{o=e.apply(r,t||[])}catch(e){return I(),n.reject(e)}return I(),n.resolve(o)},n.delay=function(e){return new n(function(n){setTimeout(n,e)})},n.isPromise=function(e){return!!(e&&e instanceof n)||S(e)},n.flush=function(){return e=b=b||new n,N(),e;var e},n}();function k(){return(k=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n}).apply(this,arguments)}function D(n,e){for(var r=0;r<n.length;r++)try{if(n[r]===e)return r}catch(n){}return-1}var M,T=Object.defineProperty,C=Date.now()%1e9,L=function(){function n(){if(this.name=void 0,this.weakmap=void 0,this.keys=void 0,this.values=void 0,C+=1,this.name="__weakmap_"+(1e9*Math.random()>>>0)+"__"+C,function(){if("undefined"==typeof WeakMap)return!1;if(void 0===Object.freeze)return!1;try{var n=new WeakMap,e={};return Object.freeze(e),n.set(e,"__testvalue__"),"__testvalue__"===n.get(e)}catch(n){return!1}}())try{this.weakmap=new WeakMap}catch(n){}this.keys=[],this.values=[]}var e=n.prototype;return e._cleanupClosedWindows=function(){for(var n=this.weakmap,e=this.keys,r=0;r<e.length;r++){var t=e[r];if(W(t)&&E(t)){if(n)try{n.delete(t)}catch(n){}e.splice(r,1),this.values.splice(r,1),r-=1}}},e.isSafeToReadWrite=function(n){if(W(n))return!1;try{n&&n.self,n&&n[this.name]}catch(n){return!1}return!0},e.set=function(n,e){if(!n)throw new Error("WeakMap expected key");var r=this.weakmap;if(r)try{r.set(n,e)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var t=this.name,o=n[t];o&&o[0]===n?o[1]=e:T(n,t,{value:[n,e],writable:!0})}else{this._cleanupClosedWindows();var i=this.keys,a=this.values,u=D(i,n);-1===u?(i.push(n),a.push(e)):a[u]=e}},e.get=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{if(e.has(n))return e.get(n)}catch(n){delete this.weakmap}if(!this.isSafeToReadWrite(n)){this._cleanupClosedWindows();var r=D(this.keys,n);if(-1===r)return;return this.values[r]}var t=n[this.name];if(t&&t[0]===n)return t[1]},e.delete=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{e.delete(n)}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var r=n[this.name];r&&r[0]===n&&(r[0]=r[1]=void 0)}else{this._cleanupClosedWindows();var t=this.keys,o=D(t,n);-1!==o&&(t.splice(o,1),this.values.splice(o,1))}},e.has=function(n){if(!n)throw new Error("WeakMap expected key");var e=this.weakmap;if(e)try{if(e.has(n))return!0}catch(n){delete this.weakmap}if(this.isSafeToReadWrite(n)){var r=n[this.name];return!(!r||r[0]!==n)}return this._cleanupClosedWindows(),-1!==D(this.keys,n)},e.getOrSet=function(n,e){if(this.has(n))return this.get(n);var r=e();return this.set(n,r),r},n}();function z(){var n="0123456789abcdef";return"xxxxxxxxxx".replace(/./g,function(){return n.charAt(Math.floor(Math.random()*n.length))})+"_"+function(n){if("function"==typeof btoa)return btoa(n);if("undefined"!=typeof Buffer)return Buffer.from(n,"utf8").toString("base64");throw new Error("Can not find window.btoa or Buffer")}((new Date).toISOString().slice(11,19).replace("T",".")).replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}function U(){}function F(n){return"[object RegExp]"===Object.prototype.toString.call(n)}function B(n,e,r){if(n.hasOwnProperty(e))return n[e];var t=r();return n[e]=t,t}Object.create(Error.prototype);var H=5e3,q=2e3,G=1e4,J=-1,K={REQUEST:"postrobot_message_request",RESPONSE:"postrobot_message_response",ACK:"postrobot_message_ack"},X={METHOD:"postrobot_method",HELLO:"postrobot_hello",OPEN_TUNNEL:"postrobot_open_tunnel"},Y="*",Z={CROSS_DOMAIN_ZALGO_PROMISE:"cross_domain_zalgo_promise",CROSS_DOMAIN_FUNCTION:"cross_domain_function",CROSS_DOMAIN_WINDOW:"cross_domain_window"};function Q(n){return void 0===n&&(n=window),n!==window?n.__post_robot_10_0_0__:n.__post_robot_10_0_0__=n.__post_robot_10_0_0__||{}}var V=function(){return{}};function $(n,e){return void 0===n&&(n="store"),void 0===e&&(e=V),B(Q(),n,function(){var n=e();return{has:function(e){return n.hasOwnProperty(e)},get:function(e,r){return n.hasOwnProperty(e)?n[e]:r},set:function(e,r){return n[e]=r,r},del:function(e){delete n[e]},getOrSet:function(e,r){return B(n,e,r)},reset:function(){n=e()},keys:function(){return Object.keys(n)}}})}var nn=function(){};function en(){var n=Q();return n.WINDOW_WILDCARD=n.WINDOW_WILDCARD||new nn,n.WINDOW_WILDCARD}function rn(n,e){return void 0===n&&(n="store"),void 0===e&&(e=V),$("windowStore").getOrSet(n,function(){var r=new L,t=function(n){return r.getOrSet(n,e)};return{has:function(e){return t(e).hasOwnProperty(n)},get:function(e,r){var o=t(e);return o.hasOwnProperty(n)?o[n]:r},set:function(e,r){return t(e)[n]=r,r},del:function(e){delete t(e)[n]},getOrSet:function(e,r){return B(t(e),n,r)}}})}function tn(){return $("instance").getOrSet("instanceID",z)}function on(n){return rn("helloPromises").getOrSet(n,function(){return new P})}function an(n,e){return(0,e.send)(n,X.HELLO,{instanceID:tn()},{domain:Y,timeout:-1}).then(function(e){var r=e.origin,t=e.data.instanceID;return on(n).resolve({win:n,domain:r}),{win:n,domain:r,instanceID:t}})}function un(n,e){var r=e.send;return rn("windowInstanceIDPromises").getOrSet(n,function(){return an(n,{send:r}).then(function(n){return n.instanceID})})}function cn(n){rn("knownWindows").set(n,!0)}var sn,fn={FUNCTION:"function",ERROR:"error",PROMISE:"promise",REGEX:"regex",DATE:"date",ARRAY:"array",OBJECT:"object",STRING:"string",NUMBER:"number",BOOLEAN:"boolean",NULL:"null",UNDEFINED:"undefined"};function dn(n){return"object"==typeof n&&null!==n&&"string"==typeof n.__type__}function ln(n){return void 0===n?fn.UNDEFINED:null===n?fn.NULL:Array.isArray(n)?fn.ARRAY:"function"==typeof n?fn.FUNCTION:"object"==typeof n?n instanceof Error?fn.ERROR:"function"==typeof n.then?fn.PROMISE:"[object RegExp]"===Object.prototype.toString.call(n)?fn.REGEX:"[object Date]"===Object.prototype.toString.call(n)?fn.DATE:fn.OBJECT:"string"==typeof n?fn.STRING:"number"==typeof n?fn.NUMBER:"boolean"==typeof n?fn.BOOLEAN:void 0}function hn(n,e){return{__type__:n,__val__:e}}var wn,pn=((sn={})[fn.FUNCTION]=function(){},sn[fn.ERROR]=function(n){var e=n.message,r=n.stack,t=n.code;return hn(fn.ERROR,{message:e,stack:r,code:t})},sn[fn.PROMISE]=function(){},sn[fn.REGEX]=function(n){return hn(fn.REGEX,n.source)},sn[fn.DATE]=function(n){return hn(fn.DATE,n.toJSON())},sn[fn.ARRAY]=function(n){return n},sn[fn.OBJECT]=function(n){return n},sn[fn.STRING]=function(n){return n},sn[fn.NUMBER]=function(n){return n},sn[fn.BOOLEAN]=function(n){return n},sn[fn.NULL]=function(n){return n},sn),vn={},mn=((wn={})[fn.FUNCTION]=function(){throw new Error("Function serialization is not implemented; nothing to deserialize")},wn[fn.ERROR]=function(n){var e=n.message,r=n.stack,t=n.code,o=new Error(e);return o.code=t,o.stack=r+"\n\n"+o.stack,o},wn[fn.PROMISE]=function(){throw new Error("Promise serialization is not implemented; nothing to deserialize")},wn[fn.REGEX]=function(n){return new RegExp(n)},wn[fn.DATE]=function(n){return new Date(n)},wn[fn.ARRAY]=function(n){return n},wn[fn.OBJECT]=function(n){return n},wn[fn.STRING]=function(n){return n},wn[fn.NUMBER]=function(n){return n},wn[fn.BOOLEAN]=function(n){return n},wn[fn.NULL]=function(n){return n},wn),yn={};function gn(){for(var n=$("idToProxyWindow"),e=0,r=n.keys();e<r.length;e++){var t=r[e];n.get(t).shouldClean()&&n.del(t)}}new P(function(n){if(window.document&&window.document.body)return n(window.document.body);var e=setInterval(function(){if(window.document&&window.document.body)return clearInterval(e),n(window.document.body)},10)});var En=function(){function n(n,e,r){var t=r.send;this.isProxyWindow=!0,this.serializedWindow=void 0,this.actualWindow=void 0,this.actualWindowPromise=void 0,this.send=void 0,this.serializedWindow=n,this.actualWindowPromise=new P,e&&this.setWindow(e),this.serializedWindow.getInstanceID=function(n){var e={};function r(){for(var r=arguments.length,t=new Array(r),o=0;o<r;o++)t[o]=arguments[o];var i=function(n){try{return JSON.stringify(Array.prototype.slice.call(n),function(n,e){return"function"==typeof e?"memoize["+function(n){if(M=M||new L,null==n||"object"!=typeof n&&"function"!=typeof n)throw new Error("Invalid object");var e=M.get(n);return e||(e=typeof n+":"+z(),M.set(n,e)),e}(e)+"]":e})}catch(n){throw new Error("Arguments not serializable -- can not be used to memoize")}}(t);return e.hasOwnProperty(i)?e[i]:(e[i]=n.apply(this,arguments).finally(function(){delete e[i]}),e[i])}return r.reset=function(){e={}},r}(this.serializedWindow.getInstanceID),this.send=t}var e=n.prototype;return e.getType=function(){return this.serializedWindow.type},e.isPopup=function(){return"popup"===this.getType()},e.isIframe=function(){return"iframe"===this.getType()},e.setLocation=function(n){var e=this;return P.try(function(){if(!e.actualWindow)return e.serializedWindow.setLocation(n);e.actualWindow.location=n}).then(function(){return e})},e.setName=function(n){var e=this;return P.try(function(){if(!e.actualWindow)return e.serializedWindow.setName(n);if(!p(e.actualWindow))throw new Error("Can not set name for window on different domain");e.actualWindow.name=n,e.actualWindow.frameElement&&e.actualWindow.frameElement.setAttribute("name",n)}).then(function(){return e})},e.close=function(){var n=this;return P.try(function(){if(!n.actualWindow)return n.serializedWindow.close();n.actualWindow.close()}).then(function(){return n})},e.focus=function(){var n=this;return P.try(function(){return n.actualWindow&&n.actualWindow.focus(),n.serializedWindow.focus()}).then(function(){return n})},e.isClosed=function(){var n=this;return P.try(function(){return n.actualWindow?E(n.actualWindow):n.serializedWindow.isClosed()})},e.getWindow=function(){return this.actualWindow},e.setWindow=function(n){this.actualWindow=n,this.actualWindowPromise.resolve(n)},e.awaitWindow=function(){return this.actualWindowPromise},e.matchWindow=function(n){var e=this;return P.try(function(){return e.actualWindow?n===e.actualWindow:P.all([e.getInstanceID(),un(n,{send:e.send})]).then(function(r){var t=r[0]===r[1];return t&&e.setWindow(n),t})})},e.unwrap=function(){return this.actualWindow||this},e.getInstanceID=function(){return this.actualWindow?un(this.actualWindow,{send:this.send}):this.serializedWindow.getInstanceID()},e.serialize=function(){return this.serializedWindow},e.shouldClean=function(){return this.actualWindow&&E(this.actualWindow)},n.unwrap=function(e){return n.isProxyWindow(e)?e.unwrap():e},n.serialize=function(e,r){var t=r.send;return gn(),n.toProxyWindow(e,{send:t}).serialize()},n.deserialize=function(e,r){var t=r.on,o=r.send;return gn(),$("idToProxyWindow").getOrSet(e.id,function(){return new n(e,null,{on:t,send:o})})},n.isProxyWindow=function(n){return Boolean(n&&!W(n)&&n.isProxyWindow)},n.toProxyWindow=function(e,r){var t=r.send;return gn(),n.isProxyWindow(e)?e:rn("winToProxyWindow").getOrSet(e,function(){var r=z();return $("idToProxyWindow").set(r,new n({id:r,type:f(e)?"popup":"iframe",getInstanceID:function(){return un(e,{send:t})},close:function(){return P.try(function(){e.close()})},focus:function(){return P.try(function(){e.focus()})},isClosed:function(){return P.try(function(){return E(e)})},setLocation:function(n){return P.try(function(){if(p(e))try{if(e.location&&"function"==typeof e.location.replace)return void e.location.replace(n)}catch(n){}e.location=n})},setName:function(n){return P.try(function(){e.name=n})}},e,{send:t}))})},n}();function _n(n,e,r,t,o){var i=rn("methodStore"),a=$("proxyWindowMethods");En.isProxyWindow(t)?a.set(n,{val:e,name:r,domain:o,source:t}):(a.del(n),i.getOrSet(t,function(){return{}})[n]={domain:o,name:r,val:e,source:t})}function On(n,e){var r=rn("methodStore"),t=$("proxyWindowMethods");return r.getOrSet(n,function(){return{}})[e]||t.get(e)}function Wn(n,e,r,t,o){!function(n){var e=o.on;$("builtinListeners").getOrSet("functionCalls",function(){return e(X.METHOD,{domain:Y},function(n){var e=n.source,r=n.origin,t=n.data,o=t.id,i=t.name,a=On(e,o);if(!a)throw new Error("Could not find method '"+t.name+"' with id: "+t.id+" in "+h(window));var u=a.source,c=a.domain,s=a.val;return P.try(function(){if(!O(c,r))throw new Error("Method '"+t.name+"' domain "+JSON.stringify(F(a.domain)?a.domain.source:a.domain)+" does not match origin "+r+" in "+h(window));if(En.isProxyWindow(u))return u.matchWindow(e).then(function(n){if(!n)throw new Error("Method call '"+t.name+"' failed - proxy window does not match source in "+h(window))})}).then(function(){return s.apply({source:e,origin:r},t.args)},function(n){return P.try(function(){if(s.onError)return s.onError(n)}).then(function(){throw n})}).then(function(n){return{result:n,id:o,name:i}})})})}();var i=r.__id__||z();n=En.unwrap(n);var a=r.__name__||r.name||t;return En.isProxyWindow(n)?(_n(i,r,a,n,e),n.awaitWindow().then(function(n){_n(i,r,a,n,e)})):_n(i,r,a,n,e),hn(Z.CROSS_DOMAIN_FUNCTION,{id:i,name:a})}function Sn(n,e,r,t){var o,i=t.on,a=t.send;return function(n,e){void 0===e&&(e=vn);var r=JSON.stringify(n,function(n){var r=this[n];if(dn(this))return r;var t=ln(r);if(!t)return r;var o=e[t]||pn[t];return o?o(r,n):r});return void 0===r?fn.UNDEFINED:r}(r,((o={})[fn.PROMISE]=function(r,t){return function(n,e,r,t,o){var i=o.on,a=o.send;return hn(Z.CROSS_DOMAIN_ZALGO_PROMISE,{then:Wn(n,e,function(n,e){return r.then(n,e)},t,{on:i,send:a})})}(n,e,r,t,{on:i,send:a})},o[fn.FUNCTION]=function(r,t){return Wn(n,e,r,t,{on:i,send:a})},o[fn.OBJECT]=function(n){return W(n)||En.isProxyWindow(n)?function(n,e,r,t){var o=t.send;return hn(Z.CROSS_DOMAIN_WINDOW,En.serialize(r,{send:o}))}(0,0,n,{on:i,send:a}):n},o))}function bn(n,e,r,t){var o,i=t.on,a=t.send;return function(n,e){if(void 0===e&&(e=yn),n!==fn.UNDEFINED)return JSON.parse(n,function(n,r){if(dn(this))return r;var t,o;if(dn(r)?(t=r.__type__,o=r.__val__):(t=ln(r),o=r),!t)return o;var i=e[t]||mn[t];return i?i(o,n):o})}(r,((o={})[Z.CROSS_DOMAIN_ZALGO_PROMISE]=function(n){return e=n.then,new P(e);var e},o[Z.CROSS_DOMAIN_FUNCTION]=function(r){return function(n,e,r,t){var o=r.id,i=r.name,a=t.send,u=function(r){function t(){var u=arguments;return En.toProxyWindow(n,{send:a}).awaitWindow().then(function(n){var c=On(n,o);return c&&c.val!==t?c.val.apply({source:window,origin:h()},u):a(n,X.METHOD,{id:o,name:i,args:Array.prototype.slice.call(u)},{domain:e,fireAndForget:r.fireAndForget}).then(function(n){if(!r.fireAndForget)return n.data.result})}).catch(function(n){throw n})}return void 0===r&&(r={}),t.__name__=i,t.__origin__=e,t.__source__=n,t.__id__=o,t.origin=e,t},c=u();return c.fireAndForget=u({fireAndForget:!0}),c}(n,e,r,{on:i,send:a})},o[Z.CROSS_DOMAIN_WINDOW]=function(n){return function(n,e,r,t){var o=t.on,i=t.send;return En.deserialize(r,{on:o,send:i})}(0,0,n,{on:i,send:a})},o))}var Rn={};function jn(n,e,r,t){var o,i=t.on,a=t.send;if(E(n))throw new Error("Window is closed");for(var u,c=Sn(n,e,((o={}).__post_robot_10_0_0__=k({id:z()},r),o),{on:i,send:a}),s=!1,f=0,d=Object.keys(Rn);f<d.length;f++){var l=d[f];try{Rn[l](n,c,e),s=!0}catch(n){u=u||n}}if(!s)throw u}Rn.postrobot_post_message=function(n,e,r){(Array.isArray(r)?r:"string"==typeof r?[r]:[Y]).map(function(e){if(0===e.indexOf(i.MOCK)){if(window.location.protocol===i.FILE)return Y;if(!w(n))throw new Error("Attempting to send messsage to mock domain "+e+", but window is actually cross-domain");return l(n)}return 0===e.indexOf(i.FILE)?Y:e}).forEach(function(r){n.postMessage(e,r)})};var xn,Nn="__domain_regex__";function An(n){return $("responseListeners").get(n)}function In(n){$("responseListeners").del(n)}function Pn(n){return $("erroredResponseListeners").has(n)}function kn(n){var e=n.name,r=n.win,t=n.domain,o=rn("requestListeners");if(r===Y&&(r=null),t===Y&&(t=null),!e)throw new Error("Name required to get request listener");for(var i=0,a=[r,en()];i<a.length;i++){var u=a[i];if(u){var c=o.get(u);if(c){var s=c[e];if(s){if(t&&"string"==typeof t){if(s[t])return s[t];if(s[Nn])for(var f=0,d=s[Nn];f<d.length;f++){var l=d[f],h=l.regex,w=l.listener;if(O(h,t))return w}}if(s[Y])return s[Y]}}}}}var Dn=((xn={})[K.REQUEST]=function(n,e,r,t){var o=t.on,i=t.send,a=kn({name:r.name,win:n,domain:e});function u(t,a,u){void 0===u&&(u={}),r.fireAndForget||E(n)||jn(n,e,k({type:t,ack:a,hash:r.hash,name:r.name},u),{on:o,send:i})}return r.name===X.METHOD&&r.data&&"string"==typeof r.data.name?r.data.name:r.name,P.all([u(K.ACK),P.try(function(){if(!a)throw new Error("No handler found for post message: "+r.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!O(a.domain,e))throw new Error("Request origin "+e+" does not match domain "+a.domain.toString());var t=r.data;return a.handler({source:n,origin:e,data:t})}).then(function(n){return u(K.RESPONSE,"success",{data:n})},function(n){return u(K.RESPONSE,"error",{error:n})})]).then(U).catch(function(n){if(a&&a.handleError)return a.handleError(n);throw n})},xn[K.ACK]=function(n,e,r){if(!Pn(r.hash)){var t=An(r.hash);if(!t)throw new Error("No handler found for post message ack for message: "+r.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!O(t.domain,e))throw new Error("Ack origin "+e+" does not match domain "+t.domain.toString());if(n!==t.win)throw new Error("Ack source does not match registered window");t.ack=!0}},xn[K.RESPONSE]=function(n,e,r){if(!Pn(r.hash)){var t,i=An(r.hash);if(!i)throw new Error("No handler found for post message response for message: "+r.name+" from "+e+" in "+window.location.protocol+"//"+window.location.host+window.location.pathname);if(!O(i.domain,e))throw new Error("Response origin "+e+" does not match domain "+(t=i.domain,Array.isArray(t)?"("+t.join(" | ")+")":o(t)?"RegExp("+t.toString():t.toString()));if(n!==i.win)throw new Error("Response source does not match registered window");In(r.hash),r.name===X.METHOD&&r.data&&"string"==typeof r.data.name?r.data.name:r.name,"error"===r.ack?i.promise.reject(r.error):"success"===r.ack&&i.promise.resolve({source:n,origin:e,data:r.data})}},xn);function Mn(n,e){var r=e.on,t=e.send,o=$("receivedMessages");if(!window||window.closed)throw new Error("Message recieved in closed window");try{if(!n.source)return}catch(n){return}var i=n.source,a=n.origin,u=function(n,e,r,t){var o,i=t.on,a=t.send;try{o=bn(e,r,n,{on:i,send:a})}catch(n){return}if(o&&"object"==typeof o&&null!==o&&(o=o.__post_robot_10_0_0__)&&"object"==typeof o&&null!==o&&o.type&&"string"==typeof o.type&&Dn[o.type])return o}(n.data,i,a,{on:r,send:t});u&&(cn(i),o.has(u.id)||(o.set(u.id,!0),E(i)&&!u.fireAndForget||Dn[u.type](i,a,u,{on:r,send:t})))}function Tn(n,e,r){if(!n)throw new Error("Expected name");if("function"==typeof e&&(r=e,e={}),!r)throw new Error("Expected handler");(e=e||{}).name=n,e.handler=r||e.handler;var t=e.window,o=e.domain,i=function n(e,r){var t=e.name,o=e.win,i=e.domain,a=rn("requestListeners");if(!t||"string"!=typeof t)throw new Error("Name required to add request listener");if(Array.isArray(o)){for(var u=[],c=0,s=o;c<s.length;c++){var f=s[c];u.push(n({name:t,domain:i,win:f},r))}return{cancel:function(){for(var n=0;n<u.length;n++)u[n].cancel()}}}if(Array.isArray(i)){for(var d=[],l=0,h=i;l<h.length;l++){var w=h[l];d.push(n({name:t,win:o,domain:w},r))}return{cancel:function(){for(var n=0;n<d.length;n++)d[n].cancel()}}}var p=kn({name:t,win:o,domain:i});if(o&&o!==Y||(o=en()),i=i||Y,p)throw o&&i?new Error("Request listener already exists for "+t+" on domain "+i.toString()+" for "+(o===en()?"wildcard":"specified")+" window"):o?new Error("Request listener already exists for "+t+" for "+(o===en()?"wildcard":"specified")+" window"):i?new Error("Request listener already exists for "+t+" on domain "+i.toString()):new Error("Request listener already exists for "+t);var v,m,y=a.getOrSet(o,function(){return{}}),g=B(y,t,function(){return{}}),E=i.toString();return F(i)?(v=B(g,Nn,function(){return[]}),m={regex:i,listener:r},v.push(m)):g[E]=r,{cancel:function(){delete g[E],m&&(v.splice(v.indexOf(m,1)),v.length||delete g[Nn]),Object.keys(g).length||delete y[t],o&&!Object.keys(y).length&&a.del(o)}}}({name:n,win:t,domain:o},{handler:e.handler,handleError:e.errorHandler||function(n){throw n},window:t,domain:o||Y,name:n});return{cancel:function(){i.cancel()}}}function Cn(n,e,r){"function"==typeof(e=e||{})&&(r=e,e={});var t,o=new P;return e.errorHandler=function(n){t.cancel(),o.reject(n)},t=Tn(n,e,function(n){if(t.cancel(),o.resolve(n),r)return r(n)}),o.cancel=t.cancel,o}function Ln(n,e,r,t){var o=(t=t||{}).domain||Y,i=t.timeout||J,a=t.timeout||H,u=t.fireAndForget||!1;return P.try(function(){if(!e)throw new Error("Expected name");if(o&&"string"!=typeof o&&!Array.isArray(o)&&!F(o))throw new TypeError("Expected domain to be a string, array, or regex");if(E(n))throw new Error("Target window is closed");var t=rn("requestPromises").getOrSet(n,function(){return[]}),c=P.try(function(){return function(n,e){var r=_(e);if(r)return r===n;if(e===n)return!1;if(function(n){if(n){try{if(n.top)return n.top}catch(n){}if(s(n)===n)return n;try{if(v(window,n)&&window.top)return window.top}catch(n){}try{if(v(n,window)&&window.top)return window.top}catch(n){}for(var e=0,r=function n(e){for(var r=[],t=0,o=m(e);t<o.length;t++){var i=o[t];r.push(i);for(var a=0,u=n(i);a<u.length;a++){var c=u[a];r.push(c)}}return r}(n);e<r.length;e++){var t=r[e];try{if(t.top)return t.top}catch(n){}if(s(t)===t)return t}}}(e)===e)return!1;for(var t=0,o=m(n);t<o.length;t++)if(o[t]===e)return!0;return!1}(window,n)?function(n,e,r){void 0===e&&(e=5e3),void 0===r&&(r="Window");var t=on(n);return-1!==e&&(t=t.timeout(e,new Error(r+" did not load after "+e+"ms"))),t}(n,a):F(o)?an(n,{send:Ln}):void 0}).then(function(a){var s=(void 0===a?{}:a).domain;if(F(o)){if(!O(o,s))throw new Error("Remote window domain "+s+" does not match regex: "+o.source);o=s}e===X.METHOD&&r&&"string"==typeof r.name&&r.name;var f=!1,d=new P;d.finally(function(){f=!0,t.splice(t.indexOf(c,1))}).catch(U);var l=e+"_"+z();if(jn(n,o,{type:K.REQUEST,hash:l,name:e,data:r,fireAndForget:u},{on:Tn,send:Ln}),u)return d.resolve();d.catch(function(){!function(n){$("erroredResponseListeners").set(n,!0)}(l),In(l)});var w={name:e,win:n,domain:o,promise:d};!function(n,e){$("responseListeners").set(n,e)}(l,w);var p=function(n){return rn("knownWindows").get(n,!1)}(n)?G:q,v=i,m=p,y=v,g=100;return setTimeout(function r(){if(!f){if(E(n))return w.ack?d.reject(new Error("Window closed for "+e+" before response")):d.reject(new Error("Window closed for "+e+" before ack"));if(m=Math.max(m-g,0),-1!==y&&(y=Math.max(y-g,0)),w.ack){if(-1===y)return;g=Math.min(y,2e3)}else{if(0===m)return d.reject(new Error("No ack for postMessage "+e+" in "+h()+" in "+p+"ms"));if(0===y)return d.reject(new Error("No response for postMessage "+e+" in "+h()+" in "+v+"ms"))}setTimeout(r,g)}},g),d});return t.push(c),c})}function zn(n,e,r){return Sn(n,e,r,{on:Tn,send:Ln})}function Un(n,e,r){return bn(n,e,r,{on:Tn,send:Ln})}function Fn(n){return En.toProxyWindow(n,{send:Ln})}function Bn(){var n,e,r,t;Q().initialized||(Q().initialized=!0,function(n){var e=n.on,r=n.send;$().getOrSet("postMessageListeners",function(){return n=window,t=function(n){!function(n,e){var r=e.on,t=e.send;try{n.source}catch(n){return}var o={source:n.source||n.sourceElement,origin:n.origin||n.originalEvent&&n.originalEvent.origin,data:n.data};if(o.source){if(!o.origin)throw new Error("Post message did not have origin domain");Mn(o,{on:r,send:t})}}(n,{on:e,send:r})},n.addEventListener("message",t),{cancel:function(){n.removeEventListener("message",t)}};var n,t})}({on:Tn,send:Ln}),function(n){var e=n.on,r=n.send;$("builtinListeners").getOrSet("helloListener",function(){var n=e(X.HELLO,{domain:Y},function(n){var e=n.source,r=n.origin;return on(e).resolve({win:e,domain:r}),{instanceID:tn()}}),t=_();return t&&an(t,{send:r}).catch(U),n})}({on:Tn,send:Ln}),e=(n={on:Tn,send:Ln}).on,r=n.send,(t=Q()).receiveMessage=t.receiveMessage||function(n){return Mn(n,{on:e,send:r})})}function Hn(n){for(var e=0,r=rn("requestPromises").get(n,[]);e<r.length;e++)r[e].reject(new Error("Window cleaned up before response")).catch(U)}r.d(e,"bridge",function(){}),r.d(e,"Promise",function(){return P}),r.d(e,"TYPES",function(){return!0}),r.d(e,"ProxyWindow",function(){return En}),r.d(e,"setup",function(){return Bn}),r.d(e,"serializeMessage",function(){return zn}),r.d(e,"deserializeMessage",function(){return Un}),r.d(e,"toProxyWindow",function(){return Fn}),r.d(e,"on",function(){return Tn}),r.d(e,"once",function(){return Cn}),r.d(e,"send",function(){return Ln}),r.d(e,"markWindowKnown",function(){return cn}),r.d(e,"cleanUpWindow",function(){return Hn}),Bn()}])}); | ||
//# sourceMappingURL=post-robot.min.js.map |
/* @flow */ | ||
/* eslint import/no-commonjs: 0 */ | ||
const { getCurrentVersion } = require('grumbler-scripts/config/webpack.config'); | ||
const pkg = require('./package.json'); | ||
module.exports = { | ||
'__POST_ROBOT__': { | ||
__POST_ROBOT__: { | ||
__GLOBAL_KEY__: `__post_robot_${ getCurrentVersion(pkg) }__`, | ||
__AUTO_SETUP__: true, | ||
__IE_POPUP_SUPPORT__: true, | ||
@@ -7,0 +13,0 @@ __GLOBAL_MESSAGE_SUPPORT__: true |
{ | ||
"name": "post-robot", | ||
"version": "9.0.36", | ||
"version": "10.0.0", | ||
"description": "Simple postMessage based server.", | ||
@@ -14,5 +14,5 @@ "main": "index.js", | ||
"babel": "babel src/ --out-dir dist/module", | ||
"webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress", | ||
"webpack": "babel-node --config-file ./node_modules/grumbler-scripts/config/.babelrc-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --display-optimization-bailout --progress", | ||
"test": "npm run lint && npm run flow-typed && npm run flow && npm run karma", | ||
"build": "npm run test && npm run babel && npm run webpack", | ||
"build": "npm run test && npm run babel && npm run webpack -- $@", | ||
"release": "./publish.sh", | ||
@@ -52,4 +52,4 @@ "release:patch": "./publish.sh patch", | ||
"devDependencies": { | ||
"flow-bin": "^0.76", | ||
"grumbler-scripts": "^2.0.18", | ||
"flow-bin": "^0.81", | ||
"grumbler-scripts": "^3", | ||
"mocha": "^4" | ||
@@ -56,0 +56,0 @@ }, |
@@ -11,3 +11,3 @@ # post-robot [:]-\\-< | ||
- Don't worry about serializing your messages; [just send javascript objects](#simple-listener-and-sender-with-error-handling) | ||
- Use [promises](#listener-with-promise-response), [callbacks](#listener-with-callback-response) or [async/await](#async--await) to wait for responses from windows you message | ||
- Use [promises](#listener-with-promise-response) or [async/await](#async--await) to wait for responses from windows you message | ||
- Set up a [secure message channel](#secure-message-channel) between two windows on a certain domain | ||
@@ -86,16 +86,2 @@ - Send messages between a [parent and a popup window](#parent-to-popup-messaging) in IE | ||
## Listener with callback response | ||
```javascript | ||
postRobot.on('getUser', { id: 1337 }, function(event, callback) { | ||
setTimeout(function() { | ||
callback(null, { | ||
id: event.data.id, | ||
name: 'Captain Pugwash' | ||
}); | ||
}, 500); | ||
}); | ||
``` | ||
## One-off listener | ||
@@ -166,10 +152,2 @@ | ||
## Send a message to the direct parent | ||
```javascript | ||
postRobot.sendToParent('getUser').then(function(event) { | ||
console.log(event.data); | ||
}); | ||
``` | ||
## Async / Await | ||
@@ -222,26 +200,2 @@ | ||
You can even set up a listener and sender instance in advance: | ||
```javascript | ||
var listener = postRobot.listener({ window: childWindow, domain: 'http://zombo.com' }); | ||
listener.on('getUser', function(event) { | ||
return { | ||
id: event.data.id, | ||
name: 'Frodo' | ||
}; | ||
}); | ||
``` | ||
```javascript | ||
var client = postRobot.client({ window: someWindow, domain: 'http://zombo.com' }); | ||
client.send('getUser', { id: 1337 }).then(function(event) { | ||
console.log(event.source, event.origin, 'Got user:', event.data.name); | ||
}).catch(function(err) { | ||
console.error(err); | ||
}); | ||
``` | ||
## Functions | ||
@@ -248,0 +202,0 @@ |
@@ -8,23 +8,11 @@ /* @flow */ | ||
import { MESSAGE_NAME, WILDCARD } from '../conf'; | ||
import { global, globalStore } from '../global'; | ||
import { getGlobal, globalStore } from '../global'; | ||
import type { SendType, ResponseMessageEvent } from '../types'; | ||
/* | ||
HERE BE DRAGONS | ||
function cleanTunnelWindows() { | ||
const tunnelWindows = globalStore('tunnelWindows'); | ||
Warning: this file may look weird. Why save the tunnel window in an Object | ||
by ID, then look it up later, rather than just using the reference from the closure scope? | ||
for (const key of tunnelWindows.keys()) { | ||
const tunnelWindow = tunnelWindows[key]; | ||
The reason is, that ends up meaning the garbage collector can never get its hands | ||
on a closed window, since our closure has continued access to it -- and post-robot | ||
has no good way to know whether to clean up the function with the closure scope. | ||
If you're editing this file, be sure to run significant memory / GC tests afterwards. | ||
*/ | ||
let tunnelWindows = globalStore('tunnelWindows'); | ||
function cleanTunnelWindows() { | ||
for (let key of tunnelWindows.keys()) { | ||
let tunnelWindow = tunnelWindows[key]; | ||
try { | ||
@@ -43,3 +31,3 @@ noop(tunnelWindow.source); | ||
type TunnelWindowDataType = { | ||
type TunnelWindowDataType = {| | ||
name : string, | ||
@@ -49,7 +37,8 @@ source : CrossDomainWindowType, | ||
sendMessage : (message : string) => void | ||
}; | ||
|}; | ||
function addTunnelWindow({ name, source, canary, sendMessage } : TunnelWindowDataType) : string { | ||
cleanTunnelWindows(); | ||
let id = uniqueID(); | ||
const id = uniqueID(); | ||
const tunnelWindows = globalStore('tunnelWindows'); | ||
tunnelWindows.set(id, { name, source, canary, sendMessage }); | ||
@@ -59,42 +48,45 @@ return id; | ||
global.openTunnelToParent = function openTunnelToParent({ name, source, canary, sendMessage } : TunnelWindowDataType) : ZalgoPromise<{ source : CrossDomainWindowType, origin : string, data : Object }> { | ||
export function setupOpenTunnelToParent({ send } : { send : SendType }) { | ||
getGlobal(window).openTunnelToParent = function openTunnelToParent({ name, source, canary, sendMessage } : TunnelWindowDataType) : ZalgoPromise<ResponseMessageEvent> { | ||
let parentWindow = getParent(window); | ||
if (!parentWindow) { | ||
throw new Error(`No parent window found to open tunnel to`); | ||
} | ||
let id = addTunnelWindow({ name, source, canary, sendMessage }); | ||
return global.send(parentWindow, MESSAGE_NAME.OPEN_TUNNEL, { | ||
name, | ||
sendMessage() { | ||
let tunnelWindow = tunnelWindows.get(id); | ||
try { | ||
// IE gets antsy if you try to even reference a closed window | ||
noop(tunnelWindow && tunnelWindow.source); | ||
} catch (err) { | ||
tunnelWindows.del(id); | ||
return; | ||
const tunnelWindows = globalStore('tunnelWindows'); | ||
const parentWindow = getParent(window); | ||
if (!parentWindow) { | ||
throw new Error(`No parent window found to open tunnel to`); | ||
} | ||
const id = addTunnelWindow({ name, source, canary, sendMessage }); | ||
return send(parentWindow, MESSAGE_NAME.OPEN_TUNNEL, { | ||
name, | ||
sendMessage() { | ||
const tunnelWindow = tunnelWindows.get(id); | ||
try { | ||
// IE gets antsy if you try to even reference a closed window | ||
noop(tunnelWindow && tunnelWindow.source); | ||
} catch (err) { | ||
tunnelWindows.del(id); | ||
return; | ||
} | ||
if (!tunnelWindow || !tunnelWindow.source || isWindowClosed(tunnelWindow.source)) { | ||
return; | ||
} | ||
try { | ||
tunnelWindow.canary(); | ||
} catch (err) { | ||
return; | ||
} | ||
tunnelWindow.sendMessage.apply(this, arguments); | ||
} | ||
if (!tunnelWindow || !tunnelWindow.source || isWindowClosed(tunnelWindow.source)) { | ||
return; | ||
} | ||
try { | ||
tunnelWindow.canary(); | ||
} catch (err) { | ||
return; | ||
} | ||
tunnelWindow.sendMessage.apply(this, arguments); | ||
} | ||
}, { domain: WILDCARD }); | ||
}; | ||
}, { domain: WILDCARD }); | ||
}; | ||
} |
@@ -5,31 +5,31 @@ /* @flow */ | ||
import { isSameDomain, getOpener, getDomain, getFrameByName, type CrossDomainWindowType } from 'cross-domain-utils/src'; | ||
import { weakMapMemoize, noop } from 'belter/src'; | ||
import { noop } from 'belter/src'; | ||
import { WINDOW_PROP } from '../conf'; | ||
import { global } from '../global'; | ||
import { getGlobal, windowStore } from '../global'; | ||
import type { OnType, SendType, ReceiveMessageType } from '../types'; | ||
import { needsBridge, registerRemoteWindow, rejectRemoteSendMessage, registerRemoteSendMessage, getBridgeName } from './common'; | ||
let awaitRemoteBridgeForWindow = weakMapMemoize((win : CrossDomainWindowType) : ZalgoPromise<?CrossDomainWindowType> => { | ||
return ZalgoPromise.try(() => { | ||
try { | ||
let frame = getFrameByName(win, getBridgeName(getDomain())); | ||
function awaitRemoteBridgeForWindow (win : CrossDomainWindowType) : ZalgoPromise<?CrossDomainWindowType> { | ||
return windowStore('remoteBridgeAwaiters').getOrSet(win, () => { | ||
return ZalgoPromise.try(() => { | ||
const frame = getFrameByName(win, getBridgeName(getDomain())); | ||
if (!frame) { | ||
return; | ||
throw new Error(`Bridge not found for domain: ${ getDomain() }`); | ||
} | ||
// $FlowFixMe | ||
if (isSameDomain(frame) && frame[WINDOW_PROP.POSTROBOT]) { | ||
if (isSameDomain(frame) && getGlobal(frame)) { | ||
return frame; | ||
} | ||
return new ZalgoPromise(resolve => { | ||
return new ZalgoPromise((resolve, reject) => { | ||
let interval; | ||
let timeout; | ||
let timeout; // eslint-disable-line prefer-const | ||
interval = setInterval(() => { | ||
interval = setInterval(() => { // eslint-disable-line prefer-const | ||
// $FlowFixMe | ||
if (frame && isSameDomain(frame) && frame[WINDOW_PROP.POSTROBOT]) { | ||
if (frame && isSameDomain(frame) && getGlobal(frame)) { | ||
clearInterval(interval); | ||
@@ -43,15 +43,11 @@ clearTimeout(timeout); | ||
clearInterval(interval); | ||
return resolve(); | ||
return reject(new Error(`Bridge not found for domain: ${ getDomain() }`)); | ||
}, 2000); | ||
}); | ||
} catch (err) { | ||
// pass | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
export function openTunnelToOpener() : ZalgoPromise<void> { | ||
export function openTunnelToOpener({ on, send, receiveMessage } : { on : OnType, send : SendType, receiveMessage : ReceiveMessageType }) : ZalgoPromise<void> { | ||
return ZalgoPromise.try(() => { | ||
const opener = getOpener(window); | ||
@@ -71,6 +67,2 @@ | ||
if (!bridge) { | ||
return rejectRemoteSendMessage(opener, new Error(`Can not register with opener: no bridge found in opener`)); | ||
} | ||
if (!window.name) { | ||
@@ -80,3 +72,4 @@ return rejectRemoteSendMessage(opener, new Error(`Can not register with opener: window does not have a name`)); | ||
return bridge[WINDOW_PROP.POSTROBOT].openTunnelToParent({ | ||
// $FlowFixMe | ||
return getGlobal(bridge).openTunnelToParent({ | ||
@@ -104,7 +97,7 @@ name: window.name, | ||
try { | ||
global.receiveMessage({ | ||
receiveMessage({ | ||
data: message, | ||
origin: this.origin, | ||
source: this.source | ||
}); | ||
}, { on, send }); | ||
} catch (err) { | ||
@@ -111,0 +104,0 @@ ZalgoPromise.reject(err); |
@@ -64,5 +64,5 @@ /* @flow */ | ||
let sanitizedDomain = domain.replace(/[^a-zA-Z0-9]+/g, '_'); | ||
const sanitizedDomain = domain.replace(/[^a-zA-Z0-9]+/g, '_'); | ||
let id = `${ BRIDGE_NAME_PREFIX }_${ sanitizedDomain }`; | ||
const id = `${ BRIDGE_NAME_PREFIX }_${ sanitizedDomain }`; | ||
@@ -76,3 +76,3 @@ return id; | ||
export let documentBodyReady = new ZalgoPromise(resolve => { | ||
export const documentBodyReady = new ZalgoPromise(resolve => { | ||
@@ -83,3 +83,3 @@ if (window.document && window.document.body) { | ||
let interval = setInterval(() => { | ||
const interval = setInterval(() => { | ||
if (window.document && window.document.body) { | ||
@@ -92,20 +92,20 @@ clearInterval(interval); | ||
let remoteWindows = windowStore('remoteWindows'); | ||
export function registerRemoteWindow(win : CrossDomainWindowType) { | ||
remoteWindows.getOrSet(win, () => new ZalgoPromise()); | ||
const remoteWindowPromises = windowStore('remoteWindowPromises'); | ||
remoteWindowPromises.getOrSet(win, () => new ZalgoPromise()); | ||
} | ||
export function findRemoteWindow(win : CrossDomainWindowType) : ZalgoPromise<(remoteWin : CrossDomainWindowType, message : string, remoteDomain : string) => void> { | ||
let remoteWin = remoteWindows.get(win); | ||
const remoteWindowPromises = windowStore('remoteWindowPromises'); | ||
const remoteWinPromise = remoteWindowPromises.get(win); | ||
if (!remoteWin) { | ||
throw new Error(`Remote window not found`); | ||
if (!remoteWinPromise) { | ||
throw new Error(`Remote window promise not found`); | ||
} | ||
return remoteWin; | ||
return remoteWinPromise; | ||
} | ||
export function registerRemoteSendMessage(win : CrossDomainWindowType, domain : string, sendMessage : (message : string) => void) { | ||
let sendMessageWrapper = (remoteWin : CrossDomainWindowType, remoteDomain : string, message : string) => { | ||
const sendMessageWrapper = (remoteWin : CrossDomainWindowType, remoteDomain : string, message : string) => { | ||
if (remoteWin !== win) { | ||
@@ -119,3 +119,3 @@ throw new Error(`Remote window does not match window`); | ||
sendMessage(message); | ||
sendMessage.fireAndForget(message); | ||
}; | ||
@@ -132,4 +132,4 @@ | ||
let messagingChild = isOpener(window, win); | ||
let messagingParent = isOpener(win, window); | ||
const messagingChild = isOpener(window, win); | ||
const messagingParent = isOpener(win, window); | ||
@@ -136,0 +136,0 @@ if (!messagingChild && !messagingParent) { |
/* @flow */ | ||
// eslint-disable-next-line import/no-unassigned-import | ||
import './bridge'; | ||
export * from './bridge'; | ||
export * from './child'; | ||
export * from './common'; | ||
export * from './parent'; | ||
export * from './setup'; |
@@ -6,70 +6,78 @@ /* @flow */ | ||
import { CONFIG, MESSAGE_NAME } from '../conf'; | ||
import { BRIDGE_TIMEOUT, MESSAGE_NAME } from '../conf'; | ||
import { awaitWindowHello } from '../lib'; | ||
import { global, windowStore, globalStore } from '../global'; | ||
import { windowStore, globalStore } from '../global'; | ||
import type { OnType, SendType, ReceiveMessageType } from '../types'; | ||
import { getBridgeName, documentBodyReady, registerRemoteSendMessage, registerRemoteWindow } from './common'; | ||
let bridges = globalStore('bridges'); | ||
let bridgeFrames = globalStore('bridgeFrames'); | ||
let popupWindowsByName = globalStore('popupWindowsByName'); | ||
let popupWindowsByWin = windowStore('popupWindowsByWin'); | ||
export function listenForOpenTunnel({ on, send, receiveMessage } : { on : OnType, send : SendType, receiveMessage : ReceiveMessageType }) { | ||
const popupWindowsByName = globalStore('popupWindowsByName'); | ||
function listenForRegister(source, domain) { | ||
global.on(MESSAGE_NAME.OPEN_TUNNEL, { window: source, domain }, ({ origin, data }) => { | ||
on(MESSAGE_NAME.OPEN_TUNNEL, ({ source, origin, data }) => { | ||
const bridgePromise = globalStore('bridges').get(origin); | ||
if (origin !== domain) { | ||
throw new Error(`Domain ${ domain } does not match origin ${ origin }`); | ||
if (!bridgePromise) { | ||
throw new Error(`Can not find bridge promise for domain ${ origin }`); | ||
} | ||
if (!data.name) { | ||
throw new Error(`Register window expected to be passed window name`); | ||
} | ||
return bridgePromise.then(bridge => { | ||
if (!data.sendMessage) { | ||
throw new Error(`Register window expected to be passed sendMessage method`); | ||
} | ||
// $FlowFixMe | ||
if (source !== bridge) { | ||
// $FlowFixMe | ||
throw new Error(`Message source does not matched registered bridge for domain ${ origin }`); | ||
} | ||
if (!popupWindowsByName.has(data.name)) { | ||
throw new Error(`Window with name ${ data.name } does not exist, or was not opened by this window`); | ||
} | ||
if (!data.name) { | ||
throw new Error(`Register window expected to be passed window name`); | ||
} | ||
// $FlowFixMe | ||
if (!popupWindowsByName.get(data.name).domain) { | ||
throw new Error(`We do not have a registered domain for window ${ data.name }`); | ||
} | ||
if (!data.sendMessage) { | ||
throw new Error(`Register window expected to be passed sendMessage method`); | ||
} | ||
// $FlowFixMe | ||
if (popupWindowsByName.get(data.name).domain !== origin) { | ||
if (!popupWindowsByName.has(data.name)) { | ||
throw new Error(`Window with name ${ data.name } does not exist, or was not opened by this window`); | ||
} | ||
// $FlowFixMe | ||
throw new Error(`Message origin ${ origin } does not matched registered window origin ${ popupWindowsByName.get(data.name).domain }`); | ||
} | ||
if (!popupWindowsByName.get(data.name).domain) { | ||
throw new Error(`We do not have a registered domain for window ${ data.name }`); | ||
} | ||
// $FlowFixMe | ||
registerRemoteSendMessage(popupWindowsByName.get(data.name).win, domain, data.sendMessage); | ||
// $FlowFixMe | ||
if (popupWindowsByName.get(data.name).domain !== origin) { | ||
// $FlowFixMe | ||
throw new Error(`Message origin ${ origin } does not matched registered window origin ${ popupWindowsByName.get(data.name).domain }`); | ||
} | ||
return { | ||
sendMessage(message) { | ||
// $FlowFixMe | ||
registerRemoteSendMessage(popupWindowsByName.get(data.name).win, origin, data.sendMessage); | ||
if (!window || window.closed) { | ||
return; | ||
} | ||
return { | ||
sendMessage(message) { | ||
let winDetails = popupWindowsByName.get(data.name); | ||
if (!window || window.closed) { | ||
return; | ||
} | ||
if (!winDetails) { | ||
return; | ||
} | ||
const winDetails = popupWindowsByName.get(data.name); | ||
try { | ||
global.receiveMessage({ | ||
data: message, | ||
origin: winDetails.domain, | ||
source: winDetails.win | ||
}); | ||
} catch (err) { | ||
ZalgoPromise.reject(err); | ||
if (!winDetails) { | ||
return; | ||
} | ||
try { | ||
receiveMessage({ | ||
data: message, | ||
origin: winDetails.domain, | ||
source: winDetails.win | ||
}, { on, send }); | ||
} catch (err) { | ||
ZalgoPromise.reject(err); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
}); | ||
}); | ||
@@ -80,3 +88,3 @@ } | ||
let iframe = document.createElement(`iframe`); | ||
const iframe = document.createElement(`iframe`); | ||
@@ -103,2 +111,3 @@ iframe.setAttribute(`name`, name); | ||
export function hasBridge(url : string, domain : string) : boolean { | ||
const bridges = globalStore('bridges'); | ||
return bridges.has(domain || getDomainFromUrl(url)); | ||
@@ -108,2 +117,5 @@ } | ||
export function openBridge(url : string, domain : string) : ZalgoPromise<CrossDomainWindowType> { | ||
const bridges = globalStore('bridges'); | ||
const bridgeFrames = globalStore('bridgeFrames'); | ||
domain = domain || getDomainFromUrl(url); | ||
@@ -117,4 +129,4 @@ | ||
let name = getBridgeName(domain); | ||
let frame = getFrameByName(window, name); | ||
const name = getBridgeName(domain); | ||
const frame = getFrameByName(window, name); | ||
@@ -125,3 +137,3 @@ if (frame) { | ||
let iframe = openBridgeFrame(name, url); | ||
const iframe = openBridgeFrame(name, url); | ||
bridgeFrames.set(domain, iframe); | ||
@@ -132,15 +144,12 @@ | ||
body.appendChild(iframe); | ||
const bridge = iframe.contentWindow; | ||
let bridge = iframe.contentWindow; | ||
listenForRegister(bridge, domain); | ||
return new ZalgoPromise((resolve, reject) => { | ||
iframe.onload = resolve; | ||
iframe.onerror = reject; | ||
iframe.addEventListener('load', resolve); | ||
iframe.addEventListener('error', reject); | ||
}).then(() => { | ||
return awaitWindowHello(bridge, CONFIG.BRIDGE_TIMEOUT, `Bridge ${ url }`); | ||
return awaitWindowHello(bridge, BRIDGE_TIMEOUT, `Bridge ${ url }`); | ||
@@ -162,4 +171,6 @@ }).then(() => { | ||
export function linkWindow({ win, name, domain } : WinDetails) : WinDetails { | ||
const popupWindowsByName = globalStore('popupWindowsByName'); | ||
const popupWindowsByWin = windowStore('popupWindowsByWin'); | ||
for (let winName of popupWindowsByName.keys()) { | ||
for (const winName of popupWindowsByName.keys()) { | ||
// $FlowFixMe | ||
@@ -171,3 +182,3 @@ if (isWindowClosed(popupWindowsByName.get(winName).win)) { | ||
let details : WinDetails = popupWindowsByWin.getOrSet(win, () => { | ||
const details : WinDetails = popupWindowsByWin.getOrSet(win, () => { | ||
if (!name) { | ||
@@ -209,19 +220,24 @@ return { win }; | ||
let windowOpen = window.open; | ||
export function listenForWindowOpen() { | ||
const windowOpen = window.open; | ||
window.open = function windowOpenWrapper(url : string, name : string, options : string, last : mixed) : mixed { | ||
let win = windowOpen.call(this, normalizeMockUrl(url), name, options, last); | ||
if (!win) { | ||
window.open = function windowOpenWrapper(url : string, name : string, options : string, last : mixed) : mixed { | ||
const win = windowOpen.call(this, normalizeMockUrl(url), name, options, last); | ||
if (!win) { | ||
return win; | ||
} | ||
linkWindow({ win, name, domain: url ? getDomainFromUrl(url) : null }); | ||
return win; | ||
} | ||
}; | ||
} | ||
linkWindow({ win, name, domain: url ? getDomainFromUrl(url) : null }); | ||
export function destroyBridges() { | ||
const bridges = globalStore('bridges'); | ||
const bridgeFrames = globalStore('bridgeFrames'); | ||
return win; | ||
}; | ||
export function destroyBridges() { | ||
for (let domain of bridgeFrames.keys()) { | ||
let frame = bridgeFrames.get(domain); | ||
for (const domain of bridgeFrames.keys()) { | ||
const frame = bridgeFrames.get(domain); | ||
if (frame && frame.parentNode) { | ||
@@ -228,0 +244,0 @@ frame.parentNode.removeChild(frame); |
@@ -6,8 +6,9 @@ /* @flow */ | ||
import { requestPromises } from './public'; | ||
import { windowStore } from './global'; | ||
export function cleanUpWindow(win : CrossDomainWindowType) { | ||
for (let promise of requestPromises.get(win, [])) { | ||
const requestPromises = windowStore('requestPromises'); | ||
for (const promise of requestPromises.get(win, [])) { | ||
promise.reject(new Error(`Window cleaned up before response`)).catch(noop); | ||
} | ||
} |
/* @flow */ | ||
import { SEND_STRATEGY } from './constants'; | ||
export const BRIDGE_TIMEOUT = 5000; | ||
export const CHILD_WINDOW_TIMEOUT = 5000; | ||
export let CONFIG : Object = { | ||
BRIDGE_TIMEOUT: 5000, | ||
CHILD_WINDOW_TIMEOUT: 5000, | ||
ACK_TIMEOUT: 2000, | ||
ACK_TIMEOUT_KNOWN: 10000, | ||
RES_TIMEOUT: __TEST__ ? 2000 : -1, | ||
ALLOWED_POST_MESSAGE_METHODS: { | ||
[ SEND_STRATEGY.POST_MESSAGE ]: true, | ||
[ SEND_STRATEGY.BRIDGE ]: true, | ||
[ SEND_STRATEGY.GLOBAL ]: true | ||
} | ||
}; | ||
export const ACK_TIMEOUT = 2000; | ||
export const ACK_TIMEOUT_KNOWN = 10000; | ||
export const RES_TIMEOUT = __TEST__ ? 2000 : -1; |
@@ -20,6 +20,2 @@ /* @flow */ | ||
export const WINDOW_PROP = { | ||
POSTROBOT: ('__postRobot__' : '__postRobot__') | ||
}; | ||
export const SEND_STRATEGY = { | ||
@@ -31,7 +27,2 @@ POST_MESSAGE: ('postrobot_post_message' : 'postrobot_post_message'), | ||
export const PROTOCOL = { | ||
MOCK: ('mock:' : 'mock:'), | ||
FILE: ('file:' : 'file:') | ||
}; | ||
export const BRIDGE_NAME_PREFIX = '__postrobot_bridge__'; | ||
@@ -38,0 +29,0 @@ export const POSTROBOT_PROXY = '__postrobot_proxy__'; |
/* @flow */ | ||
declare var __POST_ROBOT__ : { | ||
__GLOBAL_KEY__ : string, | ||
__AUTO_SETUP__ : boolean, | ||
__IE_POPUP_SUPPORT__ : boolean, | ||
@@ -5,0 +7,0 @@ __GLOBAL_MESSAGE_SUPPORT__ : boolean |
@@ -7,10 +7,8 @@ /* @flow */ | ||
import { global, globalStore, windowStore } from '../global'; | ||
import { getWildcard, type WildCard, globalStore, windowStore } from '../global'; | ||
import { WILDCARD } from '../conf'; | ||
let responseListeners = globalStore('responseListeners'); | ||
let requestListeners = windowStore('requestListeners'); | ||
let erroredResponseListeners = globalStore('erroredResponseListeners'); | ||
export function resetListeners() { | ||
const responseListeners = globalStore('responseListeners'); | ||
const erroredResponseListeners = globalStore('erroredResponseListeners'); | ||
responseListeners.reset(); | ||
@@ -20,7 +18,5 @@ erroredResponseListeners.reset(); | ||
global.WINDOW_WILDCARD = global.WINDOW_WILDCARD || new (function WindowWildcard() { /* pass */ })(); | ||
const __DOMAIN_REGEX__ = '__domain_regex__'; | ||
export type RequestListenerType = { | ||
export type RequestListenerType = {| | ||
handler : ({ source : CrossDomainWindowType, origin : string, data : mixed }) => (mixed | ZalgoPromise<mixed>), | ||
@@ -31,13 +27,14 @@ handleError : (err : mixed) => void, | ||
domain : DomainMatcher | ||
}; | ||
|}; | ||
export type ResponseListenerType = { | ||
export type ResponseListenerType = {| | ||
name : string, | ||
window : CrossDomainWindowType, | ||
win : CrossDomainWindowType, | ||
domain : DomainMatcher, | ||
respond : (err : ?mixed, result : ?mixed) => void, | ||
promise : ZalgoPromise<*>, | ||
ack? : ?boolean | ||
}; | ||
|}; | ||
export function addResponseListener(hash : string, listener : ResponseListenerType) { | ||
const responseListeners = globalStore('responseListeners'); | ||
responseListeners.set(hash, listener); | ||
@@ -47,2 +44,3 @@ } | ||
export function getResponseListener(hash : string) : ?ResponseListenerType { | ||
const responseListeners = globalStore('responseListeners'); | ||
return responseListeners.get(hash); | ||
@@ -52,2 +50,3 @@ } | ||
export function deleteResponseListener(hash : string) { | ||
const responseListeners = globalStore('responseListeners'); | ||
responseListeners.del(hash); | ||
@@ -57,2 +56,3 @@ } | ||
export function markResponseListenerErrored(hash : string) { | ||
const erroredResponseListeners = globalStore('erroredResponseListeners'); | ||
erroredResponseListeners.set(hash, true); | ||
@@ -62,6 +62,8 @@ } | ||
export function isResponseListenerErrored(hash : string) : boolean { | ||
const erroredResponseListeners = globalStore('erroredResponseListeners'); | ||
return erroredResponseListeners.has(hash); | ||
} | ||
export function getRequestListener({ name, win, domain } : { name : string, win : ?CrossDomainWindowType, domain : ?(string | RegExp) }) : ?RequestListenerType { | ||
export function getRequestListener({ name, win, domain } : { name : string, win : ?(CrossDomainWindowType | WildCard), domain : ?(string | RegExp) }) : ?RequestListenerType { | ||
const requestListeners = windowStore('requestListeners'); | ||
@@ -80,3 +82,3 @@ if (win === WILDCARD) { | ||
for (let winQualifier of [ win, global.WINDOW_WILDCARD ]) { | ||
for (const winQualifier of [ win, getWildcard() ]) { | ||
if (!winQualifier) { | ||
@@ -86,3 +88,3 @@ continue; | ||
let nameListeners = requestListeners.get(winQualifier); | ||
const nameListeners = requestListeners.get(winQualifier); | ||
@@ -93,3 +95,3 @@ if (!nameListeners) { | ||
let domainListeners = nameListeners[name]; | ||
const domainListeners = nameListeners[name]; | ||
@@ -106,3 +108,3 @@ if (!domainListeners) { | ||
if (domainListeners[__DOMAIN_REGEX__]) { | ||
for (let { regex, listener } of domainListeners[__DOMAIN_REGEX__]) { | ||
for (const { regex, listener } of domainListeners[__DOMAIN_REGEX__]) { | ||
if (matchDomain(regex, domain)) { | ||
@@ -121,3 +123,4 @@ return listener; | ||
export function addRequestListener({ name, win, domain } : { name : string, win : ?CrossDomainWindowType, domain : ?DomainMatcher }, listener : RequestListenerType) : { cancel : () => void } { | ||
export function addRequestListener({ name, win, domain } : { name : string, win : ?(CrossDomainWindowType | WildCard), domain : ?DomainMatcher }, listener : RequestListenerType) : { cancel : () => void } { | ||
const requestListeners = windowStore('requestListeners'); | ||
@@ -129,5 +132,5 @@ if (!name || typeof name !== 'string') { | ||
if (Array.isArray(win)) { | ||
let listenersCollection = []; | ||
const listenersCollection = []; | ||
for (let item of win) { | ||
for (const item of win) { | ||
listenersCollection.push(addRequestListener({ name, domain, win: item }, listener)); | ||
@@ -138,3 +141,3 @@ } | ||
cancel() { | ||
for (let cancelListener of listenersCollection) { | ||
for (const cancelListener of listenersCollection) { | ||
cancelListener.cancel(); | ||
@@ -147,5 +150,5 @@ } | ||
if (Array.isArray(domain)) { | ||
let listenersCollection = []; | ||
const listenersCollection = []; | ||
for (let item of domain) { | ||
for (const item of domain) { | ||
listenersCollection.push(addRequestListener({ name, win, domain: item }, listener)); | ||
@@ -156,3 +159,3 @@ } | ||
cancel() { | ||
for (let cancelListener of listenersCollection) { | ||
for (const cancelListener of listenersCollection) { | ||
cancelListener.cancel(); | ||
@@ -164,6 +167,6 @@ } | ||
let existingListener = getRequestListener({ name, win, domain }); | ||
const existingListener = getRequestListener({ name, win, domain }); | ||
if (!win || win === WILDCARD) { | ||
win = global.WINDOW_WILDCARD; | ||
win = getWildcard(); | ||
} | ||
@@ -175,5 +178,5 @@ | ||
if (win && domain) { | ||
throw new Error(`Request listener already exists for ${ name } on domain ${ domain.toString() } for ${ win === global.WINDOW_WILDCARD ? 'wildcard' : 'specified' } window`); | ||
throw new Error(`Request listener already exists for ${ name } on domain ${ domain.toString() } for ${ win === getWildcard() ? 'wildcard' : 'specified' } window`); | ||
} else if (win) { | ||
throw new Error(`Request listener already exists for ${ name } for ${ win === global.WINDOW_WILDCARD ? 'wildcard' : 'specified' } window`); | ||
throw new Error(`Request listener already exists for ${ name } for ${ win === getWildcard() ? 'wildcard' : 'specified' } window`); | ||
} else if (domain) { | ||
@@ -186,7 +189,7 @@ throw new Error(`Request listener already exists for ${ name } on domain ${ domain.toString() }`); | ||
let nameListeners = requestListeners.getOrSet(win, () => ({})); | ||
const nameListeners = requestListeners.getOrSet(win, () => ({})); | ||
// $FlowFixMe | ||
let domainListeners = getOrSet(nameListeners, name, () => ({})); | ||
const domainListeners = getOrSet(nameListeners, name, () => ({})); | ||
let strDomain = domain.toString(); | ||
const strDomain = domain.toString(); | ||
@@ -193,0 +196,0 @@ let regexListeners; |
@@ -6,23 +6,15 @@ /* @flow */ | ||
import { WINDOW_PROP } from '../../conf'; | ||
import { markWindowKnown, needsGlobalMessagingForBrowser } from '../../lib'; | ||
import { deserializeMessage } from '../../serialize'; | ||
import { global, globalStore } from '../../global'; | ||
import { getGlobal, globalStore } from '../../global'; | ||
import type { OnType, SendType, MessageEvent, CancelableType } from '../../types'; | ||
import { RECEIVE_MESSAGE_TYPES } from './types'; | ||
let receivedMessages = globalStore('receivedMessages'); | ||
function parseMessage(message : string, source : CrossDomainWindowType, origin : string, { on, send } : { on : OnType, send : SendType }) : ?Object { | ||
type MessageEvent = { | ||
source : CrossDomainWindowType, | ||
origin : string, | ||
data : string | ||
}; | ||
function parseMessage(message : string, source : CrossDomainWindowType, origin : string) : ?Object { | ||
let parsedMessage; | ||
try { | ||
parsedMessage = deserializeMessage(source, origin, message); | ||
parsedMessage = deserializeMessage(source, origin, message, { on, send }); | ||
} catch (err) { | ||
@@ -40,3 +32,3 @@ return; | ||
parsedMessage = parsedMessage[WINDOW_PROP.POSTROBOT]; | ||
parsedMessage = parsedMessage[__POST_ROBOT__.__GLOBAL_KEY__]; | ||
@@ -58,3 +50,4 @@ if (!parsedMessage || typeof parsedMessage !== 'object' || parsedMessage === null) { | ||
export function receiveMessage(event : MessageEvent) { | ||
export function receiveMessage(event : MessageEvent, { on, send } : { on : OnType, send : SendType }) { | ||
const receivedMessages = globalStore('receivedMessages'); | ||
@@ -80,3 +73,3 @@ if (!window || window.closed) { | ||
let message = parseMessage(data, source, origin); | ||
const message = parseMessage(data, source, origin, { on, send }); | ||
@@ -99,7 +92,20 @@ if (!message) { | ||
RECEIVE_MESSAGE_TYPES[message.type](source, origin, message); | ||
RECEIVE_MESSAGE_TYPES[message.type](source, origin, message, { on, send }); | ||
} | ||
export function messageListener(event : { source : CrossDomainWindowType, origin : string, data : string, sourceElement : CrossDomainWindowType, originalEvent? : { origin : string } }) { | ||
export function setupGlobalReceiveMessage({ on, send } : { on : OnType, send : SendType }) { | ||
const global = getGlobal(); | ||
global.receiveMessage = global.receiveMessage || (message => receiveMessage(message, { on, send })); | ||
} | ||
type ListenerEvent = {| | ||
source : CrossDomainWindowType, | ||
origin : string, | ||
data : string, | ||
sourceElement : CrossDomainWindowType, | ||
originalEvent? : { origin : string } | ||
|}; | ||
export function messageListener(event : ListenerEvent, { on, send } : { on : OnType, send : SendType }) { | ||
try { | ||
@@ -112,3 +118,3 @@ noop(event.source); | ||
// $FlowFixMe | ||
let messageEvent : MessageEvent = { | ||
const messageEvent : MessageEvent = { | ||
source: event.source || event.sourceElement, | ||
@@ -133,10 +139,13 @@ origin: event.origin || (event.originalEvent && event.originalEvent.origin), | ||
receiveMessage(messageEvent); | ||
receiveMessage(messageEvent, { on, send }); | ||
} | ||
export function listenForMessages() { | ||
// $FlowFixMe | ||
addEventListener(window, 'message', messageListener); | ||
export function listenForMessages({ on, send } : { on : OnType, send : SendType }) : CancelableType { | ||
return globalStore().getOrSet('postMessageListeners', () => { | ||
// $FlowFixMe | ||
return addEventListener(window, 'message', event => { | ||
// $FlowFixMe | ||
messageListener(event, { on, send }); | ||
}); | ||
}); | ||
} | ||
global.receiveMessage = receiveMessage; |
@@ -11,8 +11,9 @@ /* @flow */ | ||
import type { RequestMessage, AckResponseMessage, SuccessResponseMessage, ErrorResponseMessage } from '../types'; | ||
import type { OnType, SendType } from '../../types'; | ||
export let RECEIVE_MESSAGE_TYPES = { | ||
export const RECEIVE_MESSAGE_TYPES = { | ||
[ MESSAGE_TYPE.REQUEST ](source : CrossDomainWindowType, origin : string, message : RequestMessage) : ZalgoPromise<void> { | ||
[ MESSAGE_TYPE.REQUEST ](source : CrossDomainWindowType, origin : string, message : RequestMessage, { on, send } : { on : OnType, send : SendType }) : ZalgoPromise<void> { | ||
let options = getRequestListener({ name: message.name, win: source, domain: origin }); | ||
const options = getRequestListener({ name: message.name, win: source, domain: origin }); | ||
@@ -26,6 +27,6 @@ const logName = (message.name === MESSAGE_NAME.METHOD && message.data && typeof message.data.name === 'string') ? `${ message.data.name }()` : message.name; | ||
function sendResponse(type : $Values<typeof MESSAGE_TYPE>, ack? : $Values<typeof MESSAGE_ACK>, response = {}) : ZalgoPromise<void> { | ||
function sendResponse(type : $Values<typeof MESSAGE_TYPE>, ack? : $Values<typeof MESSAGE_ACK>, response = {}) { | ||
if (message.fireAndForget || isWindowClosed(source)) { | ||
return ZalgoPromise.resolve(); | ||
return; | ||
} | ||
@@ -44,3 +45,3 @@ | ||
// $FlowFixMe | ||
return sendMessage(source, origin, { | ||
sendMessage(source, origin, { | ||
type, | ||
@@ -51,3 +52,3 @@ ack, | ||
...response | ||
}); | ||
}, { on, send }); | ||
} | ||
@@ -69,3 +70,3 @@ | ||
let data = message.data; | ||
const data = message.data; | ||
@@ -96,3 +97,3 @@ return options.handler({ source, origin, data }); | ||
let options = getResponseListener(message.hash); | ||
const options = getResponseListener(message.hash); | ||
@@ -107,2 +108,6 @@ if (!options) { | ||
if (source !== options.win) { | ||
throw new Error(`Ack source does not match registered window`); | ||
} | ||
options.ack = true; | ||
@@ -117,3 +122,3 @@ }, | ||
let options = getResponseListener(message.hash); | ||
const options = getResponseListener(message.hash); | ||
@@ -128,11 +133,25 @@ if (!options) { | ||
if (source !== options.win) { | ||
throw new Error(`Response source does not match registered window`); | ||
} | ||
deleteResponseListener(message.hash); | ||
const logName = (message.name === MESSAGE_NAME.METHOD && message.data && typeof message.data.name === 'string') ? `${ message.data.name }()` : message.name; | ||
if (message.ack === MESSAGE_ACK.ERROR) { | ||
return options.respond(message.error, null); | ||
if (__DEBUG__) { | ||
console.error('receive::err', logName, origin, '\n\n', message.error); // eslint-disable-line no-console | ||
} | ||
options.promise.reject(message.error); | ||
} else if (message.ack === MESSAGE_ACK.SUCCESS) { | ||
let data = message.data; | ||
return options.respond(null, { source, origin, data }); | ||
if (__DEBUG__) { | ||
console.info('receive::res', logName, origin, '\n\n', message.data); // eslint-disable-line no-console | ||
} | ||
options.promise.resolve({ source, origin, data: message.data }); | ||
} | ||
} | ||
}; |
/* @flow */ | ||
import { isWindowClosed, type CrossDomainWindowType } from 'cross-domain-utils/src'; | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { uniqueID, stringifyError } from 'belter/src'; | ||
import { isWindowClosed, type CrossDomainWindowType, type DomainMatcher } from 'cross-domain-utils/src'; | ||
import { uniqueID } from 'belter/src'; | ||
import { CONFIG, WINDOW_PROP } from '../../conf'; | ||
import { serializeMessage } from '../../serialize'; | ||
import type { Message } from '../types'; | ||
import type { OnType, SendType } from '../../types'; | ||
import { SEND_MESSAGE_STRATEGIES } from './strategies'; | ||
export function sendMessage(win : CrossDomainWindowType, domain : string | $ReadOnlyArray<string>, message : Message) : ZalgoPromise<void> { | ||
return ZalgoPromise.try(() => { | ||
if (isWindowClosed(win)) { | ||
throw new Error('Window is closed'); | ||
export function sendMessage(win : CrossDomainWindowType, domain : DomainMatcher, message : Message, { on, send } : { on : OnType, send : SendType }) { | ||
if (isWindowClosed(win)) { | ||
throw new Error('Window is closed'); | ||
} | ||
const serializedMessage = serializeMessage(win, domain, { | ||
[ __POST_ROBOT__.__GLOBAL_KEY__ ]: { | ||
id: uniqueID(), | ||
...message | ||
} | ||
const serializedMessage = serializeMessage(win, domain, { | ||
[ WINDOW_PROP.POSTROBOT ]: { | ||
id: uniqueID(), | ||
...message | ||
} | ||
}); | ||
}, { on, send }); | ||
let success = false; | ||
let error; | ||
let messages = []; | ||
for (const strategyName of Object.keys(SEND_MESSAGE_STRATEGIES)) { | ||
try { | ||
SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain); | ||
success = true; | ||
} catch (err) { | ||
error = error || err; | ||
} | ||
} | ||
return ZalgoPromise.map(Object.keys(SEND_MESSAGE_STRATEGIES), strategyName => { | ||
return ZalgoPromise.try(() => { | ||
if (!CONFIG.ALLOWED_POST_MESSAGE_METHODS[strategyName]) { | ||
throw new Error(`Strategy disallowed: ${ strategyName }`); | ||
} | ||
return SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain); | ||
}).then(() => { | ||
messages.push(`${ strategyName }: success`); | ||
return true; | ||
}, err => { | ||
messages.push(`${ strategyName }: ${ stringifyError(err) }\n`); | ||
return false; | ||
}); | ||
}).then(results => { | ||
let success = results.some(Boolean); | ||
let status = `${ message.type } ${ message.name } ${ success ? 'success' : 'error' }:\n - ${ messages.join('\n - ') }\n`; | ||
if (!success) { | ||
throw new Error(status); | ||
} | ||
}); | ||
}); | ||
if (!success) { | ||
throw error; | ||
} | ||
} |
/* @flow */ | ||
import { isSameDomain, isSameTopWindow, isActuallySameDomain, getActualDomain, getDomain, type CrossDomainWindowType, type DomainMatcher } from 'cross-domain-utils/src'; | ||
import { isSameDomain, isSameTopWindow, isActuallySameDomain, getActualDomain, | ||
getDomain, type CrossDomainWindowType, type DomainMatcher, PROTOCOL } from 'cross-domain-utils/src'; | ||
import { SEND_STRATEGY, PROTOCOL, WILDCARD, WINDOW_PROP } from '../../conf'; | ||
import { SEND_STRATEGY, WILDCARD } from '../../conf'; | ||
import { needsGlobalMessagingForBrowser } from '../../lib'; | ||
import { getGlobal } from '../../global'; | ||
import { sendBridgeMessage, needsBridgeForBrowser, isBridge } from '../../bridge'; | ||
export let SEND_MESSAGE_STRATEGIES = {}; | ||
export const SEND_MESSAGE_STRATEGIES = {}; | ||
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.POST_MESSAGE] = (win : CrossDomainWindowType, serializedMessage : string, domain : DomainMatcher) => { | ||
@@ -53,3 +55,3 @@ | ||
domains.forEach(dom => { | ||
return win.postMessage(serializedMessage, dom); | ||
win.postMessage(serializedMessage, dom); | ||
}); | ||
@@ -60,4 +62,2 @@ }; | ||
let { sendBridgeMessage, needsBridgeForBrowser, isBridge } = require('../../bridge'); | ||
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.BRIDGE] = (win : CrossDomainWindowType, serializedMessage : string, domain : string) => { | ||
@@ -77,3 +77,3 @@ | ||
return sendBridgeMessage(win, domain, serializedMessage); | ||
sendBridgeMessage(win, domain, serializedMessage); | ||
}; | ||
@@ -99,3 +99,3 @@ } | ||
// $FlowFixMe | ||
let foreignGlobal = win[WINDOW_PROP.POSTROBOT]; | ||
const foreignGlobal = getGlobal(win); | ||
@@ -106,3 +106,3 @@ if (!foreignGlobal) { | ||
return foreignGlobal.receiveMessage({ | ||
foreignGlobal.receiveMessage({ | ||
source: window, | ||
@@ -109,0 +109,0 @@ origin: getDomain(), |
/* @flow */ | ||
import { type CrossDomainWindowType } from 'cross-domain-utils/src'; | ||
import { type CrossDomainWindowType, type SameDomainWindowType } from 'cross-domain-utils/src'; | ||
import { WeakMap } from 'cross-domain-safe-weakmap/src'; | ||
import { getOrSet } from 'belter/src'; | ||
import { WINDOW_PROP } from './conf'; | ||
export function getGlobal(win : SameDomainWindowType = window) : Object { | ||
if (win !== window) { | ||
return win[__POST_ROBOT__.__GLOBAL_KEY__]; | ||
} | ||
const global : Object = win[__POST_ROBOT__.__GLOBAL_KEY__] = win[__POST_ROBOT__.__GLOBAL_KEY__] || {}; | ||
return global; | ||
} | ||
export let global : Object = window[WINDOW_PROP.POSTROBOT] = window[WINDOW_PROP.POSTROBOT] || {}; | ||
let winStore = global.windowStore = global.windowStore || new WeakMap(); | ||
type WindowStore<T> = {| | ||
get : ((CrossDomainWindowType, T) => T) & ((CrossDomainWindowType, void) => T | void), | ||
set : (CrossDomainWindowType, T) => T, | ||
has : (CrossDomainWindowType) => boolean, | ||
del : (CrossDomainWindowType) => void, | ||
getOrSet : (CrossDomainWindowType, () => T) => T | ||
|}; | ||
type ObjectGetter = () => Object; | ||
const getObj : ObjectGetter = () => ({}); | ||
let getObj : ObjectGetter = () => ({}); | ||
type GetOrSet<T> = ((string, () => T) => T) & ((string, () => void) => void); | ||
// $FlowFixMe | ||
export function windowStore<T>(key : string, defStore? : ObjectGetter = getObj) : WindowStore<T> { | ||
function getStore(win : CrossDomainWindowType) : ObjectGetter { | ||
return winStore.getOrSet(win, defStore); | ||
} | ||
return { | ||
has: (win) => { | ||
let store = getStore(win); | ||
return store.hasOwnProperty(key); | ||
}, | ||
get: (win, defVal) => { | ||
let store = getStore(win); | ||
// $FlowFixMe | ||
return store.hasOwnProperty(key) ? store[key] : defVal; | ||
}, | ||
set: (win, val) => { | ||
let store = getStore(win); | ||
store[key] = val; | ||
return val; | ||
}, | ||
del: (win) => { | ||
let store = getStore(win); | ||
delete store[key]; | ||
}, | ||
getOrSet: (win, getter) => { | ||
let store = getStore(win); | ||
if (store.hasOwnProperty(key)) { | ||
return store[key]; | ||
} | ||
let val = getter(); | ||
store[key] = val; | ||
return val; | ||
} | ||
}; | ||
} | ||
type GlobalStore<T> = {| | ||
@@ -67,3 +25,3 @@ get : ((string, T) => T) & ((string, void) => T | void), | ||
del : (string) => void, | ||
getOrSet : (string, () => T) => T, | ||
getOrSet : GetOrSet<T>, | ||
reset : () => void, | ||
@@ -74,35 +32,85 @@ keys : () => $ReadOnlyArray<string> | ||
// $FlowFixMe | ||
export function globalStore<T : mixed>(key : string, defStore? : ObjectGetter = getObj) : GlobalStore<T> { | ||
let store = getOrSet(global, key, defStore); | ||
export function globalStore<T : mixed>(key? : string = 'store', defStore? : ObjectGetter = getObj) : GlobalStore<T> { | ||
return getOrSet(getGlobal(), key, () => { | ||
let store = defStore(); | ||
return { | ||
has: (storeKey) => { | ||
return store.hasOwnProperty(storeKey); | ||
}, | ||
get: (storeKey, defVal) => { | ||
// $FlowFixMe | ||
return store.hasOwnProperty(storeKey) ? store[storeKey] : defVal; | ||
}, | ||
set: (storeKey, val) => { | ||
store[storeKey] = val; | ||
return val; | ||
}, | ||
del: (storeKey) => { | ||
delete store[storeKey]; | ||
}, | ||
getOrSet: (storeKey, getter) => { | ||
if (store.hasOwnProperty(storeKey)) { | ||
return store[storeKey]; | ||
return { | ||
has: (storeKey) => { | ||
return store.hasOwnProperty(storeKey); | ||
}, | ||
get: (storeKey, defVal) => { | ||
// $FlowFixMe | ||
return store.hasOwnProperty(storeKey) ? store[storeKey] : defVal; | ||
}, | ||
set: (storeKey, val) => { | ||
store[storeKey] = val; | ||
return val; | ||
}, | ||
del: (storeKey) => { | ||
delete store[storeKey]; | ||
}, | ||
getOrSet: (storeKey, getter) => { | ||
// $FlowFixMe | ||
return getOrSet(store, storeKey, getter); | ||
}, | ||
reset: () => { | ||
store = defStore(); | ||
}, | ||
keys: () => { | ||
return Object.keys(store); | ||
} | ||
let val = getter(); | ||
store[storeKey] = val; | ||
return val; | ||
}, | ||
reset: () => { | ||
store = defStore(); | ||
}, | ||
keys: () => { | ||
return Object.keys(store); | ||
} | ||
}; | ||
}; | ||
}); | ||
} | ||
export class WildCard {} | ||
export function getWildcard() : WildCard { | ||
const global = getGlobal(); | ||
global.WINDOW_WILDCARD = global.WINDOW_WILDCARD || new WildCard(); | ||
return global.WINDOW_WILDCARD; | ||
} | ||
type WindowStore<T> = {| | ||
get : ((CrossDomainWindowType | WildCard, T) => T) & ((CrossDomainWindowType | WildCard, void) => T | void), | ||
set : (CrossDomainWindowType | WildCard, T) => T, | ||
has : (CrossDomainWindowType | WildCard) => boolean, | ||
del : (CrossDomainWindowType | WildCard) => void, | ||
getOrSet : (CrossDomainWindowType | WildCard, () => T) => T | ||
|}; | ||
// $FlowFixMe | ||
export function windowStore<T>(key? : string = 'store', defStore? : ObjectGetter = getObj) : WindowStore<T> { | ||
return globalStore('windowStore').getOrSet(key, () => { | ||
const winStore = new WeakMap(); | ||
const getStore = (win : CrossDomainWindowType | WildCard) : ObjectGetter => { | ||
return winStore.getOrSet(win, defStore); | ||
}; | ||
return { | ||
has: (win) => { | ||
const store = getStore(win); | ||
return store.hasOwnProperty(key); | ||
}, | ||
get: (win, defVal) => { | ||
const store = getStore(win); | ||
// $FlowFixMe | ||
return store.hasOwnProperty(key) ? store[key] : defVal; | ||
}, | ||
set: (win, val) => { | ||
const store = getStore(win); | ||
store[key] = val; | ||
return val; | ||
}, | ||
del: (win) => { | ||
const store = getStore(win); | ||
delete store[key]; | ||
}, | ||
getOrSet: (win, getter) => { | ||
const store = getStore(win); | ||
return getOrSet(store, key, getter); | ||
} | ||
}; | ||
}); | ||
} |
/* @flow */ | ||
// eslint-disable-next-line import/no-namespace | ||
import * as INTERFACE from './interface'; | ||
import { setup } from './setup'; | ||
import { setupBridge, openBridge, linkWindow, linkUrl, isBridge, needsBridge, needsBridgeForBrowser, hasBridge, | ||
needsBridgeForWin, needsBridgeForDomain, destroyBridges } from './bridge'; | ||
export * from './interface'; | ||
export default INTERFACE; | ||
export { ZalgoPromise as Promise } from 'zalgo-promise/src'; | ||
export * from './types'; | ||
export { ProxyWindow } from './serialize'; | ||
export { setup, serializeMessage, deserializeMessage, toProxyWindow } from './setup'; | ||
export { on, once, send } from './public'; | ||
export { markWindowKnown } from './lib'; | ||
export { cleanUpWindow } from './clean'; | ||
export let bridge; | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
bridge = { setupBridge, openBridge, linkWindow, linkUrl, isBridge, needsBridge, | ||
needsBridgeForBrowser, hasBridge, needsBridgeForWin, needsBridgeForDomain, destroyBridges }; | ||
} | ||
if (__POST_ROBOT__.__AUTO_SETUP__) { | ||
setup(); | ||
} |
@@ -5,23 +5,26 @@ /* @flow */ | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { noop, uniqueID, once, weakMapMemoizePromise } from 'belter/src'; | ||
import { noop, uniqueID } from 'belter/src'; | ||
import { MESSAGE_NAME, WILDCARD } from '../conf'; | ||
import { global, windowStore } from '../global'; | ||
import { windowStore, globalStore } from '../global'; | ||
import type { OnType, SendType, CancelableType } from '../types'; | ||
global.instanceID = global.instanceID || uniqueID(); | ||
let helloPromises = windowStore('helloPromises'); | ||
function getInstanceID() : string { | ||
return globalStore('instance').getOrSet('instanceID', uniqueID); | ||
} | ||
function getHelloPromise(win : CrossDomainWindowType) : ZalgoPromise<{ win : CrossDomainWindowType, domain : string }> { | ||
const helloPromises = windowStore('helloPromises'); | ||
return helloPromises.getOrSet(win, () => new ZalgoPromise()); | ||
} | ||
const listenForHello = once(() => { | ||
global.on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, ({ source, origin }) => { | ||
function listenForHello({ on } : { on : OnType }) : CancelableType { | ||
return on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, ({ source, origin }) => { | ||
getHelloPromise(source).resolve({ win: source, domain: origin }); | ||
return { instanceID: global.instanceID }; | ||
return { instanceID: getInstanceID() }; | ||
}); | ||
}); | ||
} | ||
export function sayHello(win : CrossDomainWindowType) : ZalgoPromise<{ win : CrossDomainWindowType, domain : string, instanceID : string }> { | ||
return global.send(win, MESSAGE_NAME.HELLO, { instanceID: global.instanceID }, { domain: WILDCARD, timeout: -1 }) | ||
export function sayHello(win : CrossDomainWindowType, { send } : { send : SendType }) : ZalgoPromise<{ win : CrossDomainWindowType, domain : string, instanceID : string }> { | ||
return send(win, MESSAGE_NAME.HELLO, { instanceID: getInstanceID() }, { domain: WILDCARD, timeout: -1 }) | ||
.then(({ origin, data: { instanceID } }) => { | ||
@@ -33,13 +36,19 @@ getHelloPromise(win).resolve({ win, domain: origin }); | ||
export let getWindowInstanceID = weakMapMemoizePromise((win : CrossDomainWindowType) : ZalgoPromise<string> => { | ||
return sayHello(win).then(({ instanceID }) => instanceID); | ||
}); | ||
export function getWindowInstanceID(win : CrossDomainWindowType, { send } : { send : SendType }) : ZalgoPromise<string> { | ||
return windowStore('windowInstanceIDPromises').getOrSet(win, () => { | ||
return sayHello(win, { send }).then(({ instanceID }) => instanceID); | ||
}); | ||
} | ||
export function initHello() { | ||
listenForHello(); | ||
export function initHello({ on, send } : { on : OnType, send : SendType }) : CancelableType { | ||
return globalStore('builtinListeners').getOrSet('helloListener', () => { | ||
const listener = listenForHello({ on }); | ||
let parent = getAncestor(); | ||
if (parent) { | ||
sayHello(parent).catch(noop); | ||
} | ||
const parent = getAncestor(); | ||
if (parent) { | ||
sayHello(parent, { send }).catch(noop); | ||
} | ||
return listener; | ||
}); | ||
} | ||
@@ -46,0 +55,0 @@ |
@@ -7,5 +7,4 @@ /* @flow */ | ||
let knownWindows = windowStore('knownWindows'); | ||
export function markWindowKnown(win : CrossDomainWindowType) { | ||
const knownWindows = windowStore('knownWindows'); | ||
knownWindows.set(win, true); | ||
@@ -15,3 +14,4 @@ } | ||
export function isWindowKnown(win : CrossDomainWindowType) : boolean { | ||
const knownWindows = windowStore('knownWindows'); | ||
return knownWindows.get(win, false); | ||
} |
/* @flow */ | ||
import { getAncestor } from 'cross-domain-utils/src'; | ||
export * from './client'; | ||
export * from './server'; | ||
export * from './config'; | ||
export let parent = getAncestor(); | ||
export * from './on'; | ||
export * from './send'; |
@@ -5,14 +5,11 @@ /* @flow */ | ||
import { ZalgoPromise } from 'zalgo-promise/src'; | ||
import { once, uniqueID, isRegex } from 'belter/src'; | ||
import { uniqueID, isRegex } from 'belter/src'; | ||
import { serializeType, type CustomSerializedType } from 'universal-serialize/src'; | ||
import { MESSAGE_NAME, WILDCARD, SERIALIZATION_TYPE } from '../conf'; | ||
import { global, windowStore, globalStore } from '../global'; | ||
import { windowStore, globalStore } from '../global'; | ||
import type { OnType, SendType, CancelableType } from '../types'; | ||
import { ProxyWindow } from './window'; | ||
let methodStore = windowStore('methodStore'); | ||
let proxyWindowMethods = globalStore('proxyWindowMethods'); | ||
global.listeningForFunctions = global.listeningForFunctions || false; | ||
type StoredMethod = {| | ||
@@ -26,2 +23,5 @@ name : string, | ||
function addMethod(id : string, val : Function, name : string, source : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher) { | ||
const methodStore = windowStore('methodStore'); | ||
const proxyWindowMethods = globalStore('proxyWindowMethods'); | ||
if (ProxyWindow.isProxyWindow(source)) { | ||
@@ -32,3 +32,3 @@ proxyWindowMethods.set(id, { val, name, domain, source }); | ||
// $FlowFixMe | ||
let methods = methodStore.getOrSet(source, () => ({})); | ||
const methods = methodStore.getOrSet(source, () => ({})); | ||
methods[id] = { domain, name, val, source }; | ||
@@ -39,19 +39,15 @@ } | ||
function lookupMethod(source : CrossDomainWindowType, id : string) : ?StoredMethod { | ||
let methods = methodStore.getOrSet(source, () => ({})); | ||
const methodStore = windowStore('methodStore'); | ||
const proxyWindowMethods = globalStore('proxyWindowMethods'); | ||
const methods = methodStore.getOrSet(source, () => ({})); | ||
return methods[id] || proxyWindowMethods.get(id); | ||
} | ||
const listenForFunctionCalls = once(() => { | ||
if (global.listeningForFunctions) { | ||
return; | ||
} | ||
function listenForFunctionCalls({ on } : { on : OnType }) : CancelableType { | ||
return globalStore('builtinListeners').getOrSet('functionCalls', () => { | ||
return on(MESSAGE_NAME.METHOD, { domain: WILDCARD }, ({ source, origin, data } : { source : CrossDomainWindowType, origin : string, data : Object }) => { | ||
const { id, name } = data; | ||
global.listeningForFunctions = true; | ||
global.on(MESSAGE_NAME.METHOD, { origin: WILDCARD }, ({ source, origin, data } : { source : CrossDomainWindowType, origin : string, data : Object }) => { | ||
let { id, name } = data; | ||
return ZalgoPromise.try(() => { | ||
let meth = lookupMethod(source, id); | ||
const meth = lookupMethod(source, id); | ||
if (!meth) { | ||
@@ -61,4 +57,4 @@ throw new Error(`Could not find method '${ data.name }' with id: ${ data.id } in ${ getDomain(window) }`); | ||
let { source: methodSource, domain, val } = meth; | ||
const { source: methodSource, domain, val } = meth; | ||
return ZalgoPromise.try(() => { | ||
@@ -72,3 +68,3 @@ if (!matchDomain(domain, origin)) { | ||
// $FlowFixMe | ||
return methodSource.matchWindow(source).then(match => { // eslint-disable-line max-nested-callbacks | ||
return methodSource.matchWindow(source).then(match => { | ||
if (!match) { | ||
@@ -82,7 +78,7 @@ throw new Error(`Method call '${ data.name }' failed - proxy window does not match source in ${ getDomain(window) }`); | ||
}, err => { | ||
return ZalgoPromise.try(() => { // eslint-disable-line max-nested-callbacks | ||
return ZalgoPromise.try(() => { | ||
if (val.onError) { | ||
return val.onError(err); | ||
} | ||
}).then(() => { // eslint-disable-line max-nested-callbacks | ||
}).then(() => { | ||
throw err; | ||
@@ -95,3 +91,3 @@ }); | ||
}); | ||
}); | ||
} | ||
@@ -103,8 +99,8 @@ export type SerializedFunction = CustomSerializedType<typeof SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION, { | ||
export function serializeFunction<T>(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, val : () => ZalgoPromise<T> | T, key : string) : SerializedFunction { | ||
listenForFunctionCalls(); | ||
export function serializeFunction<T>(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, val : () => ZalgoPromise<T> | T, key : string, { on } : { on : OnType }) : SerializedFunction { | ||
listenForFunctionCalls({ on }); | ||
let id = val.__id__ || uniqueID(); | ||
const id = val.__id__ || uniqueID(); | ||
destination = ProxyWindow.unwrap(destination); | ||
let name = val.__name__ || val.name || key; | ||
const name = val.__name__ || val.name || key; | ||
@@ -125,3 +121,3 @@ if (ProxyWindow.isProxyWindow(destination)) { | ||
export function deserializeFunction<T>(source : CrossDomainWindowType | ProxyWindow, origin : string, { id, name } : { id : string, name : string }) : (...args : $ReadOnlyArray<mixed>) => ZalgoPromise<T> { | ||
export function deserializeFunction<T>(source : CrossDomainWindowType | ProxyWindow, origin : string, { id, name } : { id : string, name : string }, { send } : { send : SendType }) : (...args : $ReadOnlyArray<mixed>) => ZalgoPromise<T> { | ||
const getDeserializedFunction = (opts? : Object = {}) => { | ||
@@ -135,4 +131,4 @@ function crossDomainFunctionWrapper<X : mixed>() : ZalgoPromise<X> { | ||
return ProxyWindow.toProxyWindow(source).awaitWindow().then(win => { | ||
let meth = lookupMethod(win, id); | ||
return ProxyWindow.toProxyWindow(source, { send }).awaitWindow().then(win => { | ||
const meth = lookupMethod(win, id); | ||
@@ -142,3 +138,3 @@ if (meth && meth.val !== crossDomainFunctionWrapper) { | ||
} else { | ||
return global.send(win, MESSAGE_NAME.METHOD, { id, name, args: Array.prototype.slice.call(arguments) }, { domain: origin, fireAndForget: opts.fireAndForget }) | ||
return send(win, MESSAGE_NAME.METHOD, { id, name, args: Array.prototype.slice.call(arguments) }, { domain: origin, fireAndForget: opts.fireAndForget }) | ||
.then(res => { | ||
@@ -171,3 +167,3 @@ if (!opts.fireAndForget) { | ||
let crossDomainFunctionWrapper = getDeserializedFunction(); | ||
const crossDomainFunctionWrapper = getDeserializedFunction(); | ||
crossDomainFunctionWrapper.fireAndForget = getDeserializedFunction({ fireAndForget: true }); | ||
@@ -174,0 +170,0 @@ |
@@ -8,2 +8,3 @@ /* @flow */ | ||
import { SERIALIZATION_TYPE } from '../conf'; | ||
import type { OnType, SendType } from '../types'; | ||
@@ -17,5 +18,5 @@ import { serializeFunction, type SerializedFunction } from './function'; | ||
export function serializePromise(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, val : Thenable, key : string) : SerializedPromise { | ||
export function serializePromise(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, val : Thenable, key : string, { on, send } : { on : OnType, send : SendType }) : SerializedPromise { | ||
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, { | ||
then: serializeFunction(destination, domain, (resolve, reject) => val.then(resolve, reject), key) | ||
then: serializeFunction(destination, domain, (resolve, reject) => val.then(resolve, reject), key, { on, send }) | ||
}); | ||
@@ -22,0 +23,0 @@ } |
@@ -7,2 +7,3 @@ /* @flow */ | ||
import { SERIALIZATION_TYPE } from '../conf'; | ||
import type { OnType, SendType } from '../types'; | ||
@@ -13,8 +14,8 @@ import { serializeFunction, deserializeFunction, type SerializedFunction } from './function'; | ||
export function serializeMessage<T : mixed>(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, obj : T) : string { | ||
export function serializeMessage<T : mixed>(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, obj : T, { on, send } : { on : OnType, send : SendType }) : string { | ||
return serialize(obj, { | ||
[ TYPE.PROMISE ]: (val : Thenable, key : string) : SerializedPromise => serializePromise(destination, domain, val, key), | ||
[ TYPE.FUNCTION ]: (val : Function, key : string) : SerializedFunction => serializeFunction(destination, domain, val, key), | ||
[ TYPE.PROMISE ]: (val : Thenable, key : string) : SerializedPromise => serializePromise(destination, domain, val, key, { on, send }), | ||
[ TYPE.FUNCTION ]: (val : Function, key : string) : SerializedFunction => serializeFunction(destination, domain, val, key, { on, send }), | ||
[ TYPE.OBJECT ]: (val : CrossDomainWindowType) : Object | SerializedWindow => { | ||
return (isWindow(val) || ProxyWindow.isProxyWindow(val)) ? serializeWindow(destination, domain, val) : val; | ||
return (isWindow(val) || ProxyWindow.isProxyWindow(val)) ? serializeWindow(destination, domain, val, { on, send }) : val; | ||
} | ||
@@ -24,8 +25,8 @@ }); | ||
export function deserializeMessage<T : mixed>(source : CrossDomainWindowType | ProxyWindow, origin : string, message : string) : T { | ||
export function deserializeMessage<T : mixed>(source : CrossDomainWindowType | ProxyWindow, origin : string, message : string, { on, send } : { on : OnType, send : SendType }) : T { | ||
return deserialize(message, { | ||
[ SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE ]: (serializedPromise) => deserializePromise(source, origin, serializedPromise), | ||
[ SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION ]: (serializedFunction) => deserializeFunction(source, origin, serializedFunction), | ||
[ SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW ]: (serializedWindow) => deserializeWindow(source, origin, serializedWindow) | ||
[ SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION ]: (serializedFunction) => deserializeFunction(source, origin, serializedFunction, { on, send }), | ||
[ SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW ]: (serializedWindow) => deserializeWindow(source, origin, serializedWindow, { on, send }) | ||
}); | ||
} |
@@ -11,8 +11,8 @@ /* @flow */ | ||
import { getWindowInstanceID } from '../lib'; | ||
import { linkWindow } from '../bridge'; | ||
import type { OnType, SendType } from '../types'; | ||
let winToProxyWindow = windowStore('winToProxyWindow'); | ||
let idToProxyWindow = globalStore('idToProxyWindow'); | ||
function cleanupProxyWindows() { | ||
for (let id of idToProxyWindow.keys()) { | ||
const idToProxyWindow = globalStore('idToProxyWindow'); | ||
for (const id of idToProxyWindow.keys()) { | ||
// $FlowFixMe | ||
@@ -42,4 +42,5 @@ if (idToProxyWindow.get(id).shouldClean()) { | ||
actualWindowPromise : ZalgoPromise<CrossDomainWindowType> | ||
send : SendType | ||
constructor(serializedWindow : SerializedProxyWindow, actualWindow? : CrossDomainWindowType) { | ||
constructor(serializedWindow : SerializedProxyWindow, actualWindow? : ?CrossDomainWindowType, { send } : { send : SendType }) { | ||
this.serializedWindow = serializedWindow; | ||
@@ -51,2 +52,3 @@ this.actualWindowPromise = new ZalgoPromise(); | ||
this.serializedWindow.getInstanceID = memoizePromise(this.serializedWindow.getInstanceID); | ||
this.send = send; | ||
} | ||
@@ -91,3 +93,3 @@ | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
const { linkWindow } = require('../bridge'); | ||
linkWindow({ win: this.actualWindow, name }); | ||
@@ -152,5 +154,5 @@ } | ||
this.getInstanceID(), | ||
getWindowInstanceID(win) | ||
getWindowInstanceID(win, { send: this.send }) | ||
]).then(([ proxyInstanceID, knownWindowInstanceID ]) => { | ||
let match = proxyInstanceID === knownWindowInstanceID; | ||
const match = proxyInstanceID === knownWindowInstanceID; | ||
@@ -172,3 +174,3 @@ if (match) { | ||
if (this.actualWindow) { | ||
return getWindowInstanceID(this.actualWindow); | ||
return getWindowInstanceID(this.actualWindow, { send: this.send }); | ||
} else { | ||
@@ -194,13 +196,13 @@ return this.serializedWindow.getInstanceID(); | ||
static serialize(win : CrossDomainWindowType | ProxyWindow) : SerializedProxyWindow { | ||
static serialize(win : CrossDomainWindowType | ProxyWindow, { send } : { send : SendType }) : SerializedProxyWindow { | ||
cleanupProxyWindows(); | ||
return ProxyWindow.toProxyWindow(win).serialize(); | ||
return ProxyWindow.toProxyWindow(win, { send }).serialize(); | ||
} | ||
static deserialize(serializedWindow : SerializedProxyWindow) : ProxyWindow { | ||
static deserialize(serializedWindow : SerializedProxyWindow, { on, send } : { on : OnType, send : SendType }) : ProxyWindow { | ||
cleanupProxyWindows(); | ||
return idToProxyWindow.getOrSet(serializedWindow.id, () => { | ||
return new ProxyWindow(serializedWindow); | ||
return globalStore('idToProxyWindow').getOrSet(serializedWindow.id, () => { | ||
return new ProxyWindow(serializedWindow, null, { on, send }); | ||
}); | ||
@@ -214,3 +216,3 @@ } | ||
static toProxyWindow(win : CrossDomainWindowType | ProxyWindow) : ProxyWindow { | ||
static toProxyWindow(win : CrossDomainWindowType | ProxyWindow, { send } : { send : SendType }) : ProxyWindow { | ||
cleanupProxyWindows(); | ||
@@ -224,10 +226,11 @@ | ||
// $FlowFixMe | ||
return winToProxyWindow.getOrSet(win, () => { | ||
let id = uniqueID(); | ||
return windowStore('winToProxyWindow').getOrSet(win, () => { | ||
const id = uniqueID(); | ||
return idToProxyWindow.set(id, new ProxyWindow({ | ||
return globalStore('idToProxyWindow').set(id, new ProxyWindow({ | ||
id, | ||
// $FlowFixMe | ||
type: getOpener(win) ? WINDOW_TYPE.POPUP : WINDOW_TYPE.IFRAME, | ||
getInstanceID: () => getWindowInstanceID(win), | ||
// $FlowFixMe | ||
getInstanceID: () => getWindowInstanceID(win, { send }), | ||
close: () => ZalgoPromise.try(() => { | ||
@@ -262,3 +265,2 @@ win.close(); | ||
if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { | ||
const { linkWindow } = require('../bridge'); | ||
// $FlowFixMe | ||
@@ -271,3 +273,3 @@ linkWindow({ win, name }); | ||
// $FlowFixMe | ||
}, win)); | ||
}, win, { send })); | ||
}); | ||
@@ -279,8 +281,8 @@ } | ||
export function serializeWindow(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, win : CrossDomainWindowType) : SerializedWindow { | ||
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW, ProxyWindow.serialize(win)); | ||
export function serializeWindow(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, win : CrossDomainWindowType, { send } : { send : SendType }) : SerializedWindow { | ||
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW, ProxyWindow.serialize(win, { send })); | ||
} | ||
export function deserializeWindow(source : CrossDomainWindowType | ProxyWindow, origin : string, win : SerializedProxyWindow) : ProxyWindow { | ||
return ProxyWindow.deserialize(win); | ||
export function deserializeWindow(source : CrossDomainWindowType | ProxyWindow, origin : string, win : SerializedProxyWindow, { on, send } : { on : OnType, send : SendType }) : ProxyWindow { | ||
return ProxyWindow.deserialize(win, { on, send }); | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
93
1456862
9282
275