Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sendResponse(type : $Values, ack? : $Values, response = {}) {
if (message.fireAndForget || isWindowClosed(source)) {
return;
}
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
}
}
try {
// $FlowFixMe
sendMessage(source, origin, {
export function linkWindow({ win, name, domain } : WinDetails) : WinDetails {
const popupWindowsByName = globalStore('popupWindowsByName');
const popupWindowsByWin = windowStore('popupWindowsByWin');
for (const winName of popupWindowsByName.keys()) {
// $FlowFixMe
const details = popupWindowsByName.get(winName);
if (!details || isWindowClosed(details.win)) {
popupWindowsByName.del(winName);
}
}
if (isWindowClosed(win)) {
return { win, name, domain };
}
const details = popupWindowsByWin.getOrSet(win, () : WinDetails => {
if (!name) {
return { win };
}
return popupWindowsByName.getOrSet(name, () : WinDetails => {
return { win, 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);
}
}).then(openedWindow => {
if (!openedWindow || isWindowClosed(openedWindow)) {
throw new Error(`Expected win to be open`);
}
return openedWindow;
});
}
}
} else {
targetWindow = options.window;
}
if (!targetWindow) {
throw new Error('Expected options.window to be a window object, iframe, or iframe element id.');
}
var win = targetWindow;
domain = options.domain || WILDCARD;
var hash = options.name + '_' + uniqueID();
if (isWindowClosed(win)) {
throw new Error('Target window is closed');
}
var hasResult = false;
var reqPromises = requestPromises.getOrSet(win, function () {
return [];
});
var requestPromise = ZalgoPromise['try'](function () {
if (isAncestor(window, win)) {
return awaitWindowHello(win, options.timeout || CONFIG.CHILD_WINDOW_TIMEOUT);
}
}).then(function () {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
let cycle = () => {
if (hasResult) {
return;
}
if (isWindowClosed(win)) {
if (!responseListener.ack) {
return reject(new Error(`Window closed for ${ name } before ack`));
}
return reject(new Error(`Window closed for ${ name } before response`));
}
ackTimeout = Math.max(ackTimeout - cycleTime, 0);
if (resTimeout !== -1) {
resTimeout = Math.max(resTimeout - cycleTime, 0);
}
let hasAck = responseListener.ack;
if (hasAck) {
var cycle = function cycle() {
if (hasResult) {
return;
}
if (isWindowClosed(win)) {
if (!responseListener.ack) {
return reject(new Error('Window closed for ' + name + ' before ack'));
}
return reject(new Error('Window closed for ' + name + ' before response'));
}
ackTimeout = Math.max(ackTimeout - cycleTime, 0);
if (resTimeout !== -1) {
resTimeout = Math.max(resTimeout - cycleTime, 0);
}
var hasAck = responseListener.ack;
if (hasAck) {
const message = parseMessage(data, source, origin, { on, send });
if (!message) {
return;
}
markWindowKnown(source);
if (receivedMessages.has(message.id)) {
return;
}
receivedMessages.set(message.id, true);
if (isWindowClosed(source) && !message.fireAndForget) {
return;
}
if (message.origin.indexOf(PROTOCOL.FILE) === 0) {
origin = `${ PROTOCOL.FILE }//`;
}
RECEIVE_MESSAGE_TYPES[message.type](source, origin, message, { on, send });
}
}
} else {
targetWindow = options.window;
}
if (!targetWindow) {
throw new Error('Expected options.window to be a window object, iframe, or iframe element id.');
}
const win = targetWindow;
domain = options.domain || WILDCARD;
let hash = `${ options.name }_${ uniqueID() }`;
if (isWindowClosed(win)) {
throw new Error('Target window is closed');
}
let hasResult = false;
let reqPromises = requestPromises.getOrSet(win, () => []);
let requestPromise = ZalgoPromise.try(() => {
if (isAncestor(window, win)) {
return awaitWindowHello(win, options.timeout || CONFIG.CHILD_WINDOW_TIMEOUT);
}
}).then(({ domain: origin } = {}) => {
if (isRegex(domain) && !origin) {
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(),
origin: getDomain(window),
...message
}
}, { on, send });
const strategies = Object.keys(SEND_MESSAGE_STRATEGIES);
const errors = [];
for (const strategyName of strategies) {
try {