How to use cross-domain-utils - 10 common examples

To help you get started, we’ve selected a few cross-domain-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github krakenjs / post-robot / src / drivers / receive / types.js View on Github external
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, {
github krakenjs / zoid / src / component / parent / index.js View on Github external
getPropsForChild(domain : string | RegExp) : (BuiltInPropsType & P) {

        let result = {};

        for (let key of Object.keys(this.props)) {
            let prop = this.component.getProp(key);

            if (prop && prop.sendToChild === false) {
                continue;
            }

            if (prop && prop.sameDomain && !matchDomain(domain, getDomain(window))) {
                continue;
            }

            // $FlowFixMe
            result[key] = this.props[key];
        }

        // $FlowFixMe
        return result;
    }
github krakenjs / zoid / dist / module / component / child / index.js View on Github external
var type = _ref.type,
            value = _ref.value,
            uid = _ref.uid;

        var props = void 0;

        if (type === INITIAL_PROPS.RAW) {
            props = value;
        } else if (type === INITIAL_PROPS.UID) {

            if (!isSameDomain(parentComponentWindow)) {
                if (window.location.protocol === 'file:') {
                    throw new Error('Can not get props from file:// domain');
                }

                throw new Error('Parent component window is on a different domain - expected ' + getDomain() + ' - can not retrieve props');
            }

            var global = globalFor(parentComponentWindow);

            if (!global) {
                throw new Error('Can not find global for parent component - can not retrieve props');
            }

            props = global.props[uid];
        }

        if (!props) {
            throw new Error('Initial props not found');
        }

        return deserializeMessage(parentComponentWindow, domain, props);
github krakenjs / post-robot / src / bridge / parent.js View on Github external
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 };
        });
github krakenjs / post-robot / src / bridge / bridge.js View on Github external
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);
            }
github krakenjs / post-robot / src / drivers / send / strategies.js View on Github external
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.GLOBAL] = (win : CrossDomainWindowType, serializedMessage : string) => {

        if (!needsGlobalMessagingForBrowser()) {
            throw new Error(`Global messaging not needed for browser`);
        }

        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`);
        }

        // $FlowFixMe
        const foreignGlobal = getGlobal(win);

        if (!foreignGlobal) {
            throw new Error(`Can not find postRobot global on foreign window`);
        }

        foreignGlobal.receiveMessage({
            source: window,
github krakenjs / post-robot / src / bridge / child.js View on Github external
interval = setInterval(() => { // eslint-disable-line prefer-const
                    if (frame && isSameDomain(frame) && getGlobal(assertSameDomain(frame))) {
                        clearInterval(interval);
                        clearTimeout(timeout);
                        return resolve(frame);
                    }
                }, 100);
github krakenjs / zoid / dist / module / component / child / index.js View on Github external
ChildComponent.prototype.getPropsByRef = function getPropsByRef(parentComponentWindow, domain, _ref) {
        var type = _ref.type,
            value = _ref.value,
            uid = _ref.uid;

        var props = void 0;

        if (type === INITIAL_PROPS.RAW) {
            props = value;
        } else if (type === INITIAL_PROPS.UID) {

            if (!isSameDomain(parentComponentWindow)) {
                if (window.location.protocol === 'file:') {
                    throw new Error('Can not get props from file:// domain');
                }

                throw new Error('Parent component window is on a different domain - expected ' + getDomain() + ' - can not retrieve props');
            }

            var global = globalFor(parentComponentWindow);

            if (!global) {
                throw new Error('Can not find global for parent component - can not retrieve props');
            }

            props = global.props[uid];
        }
github paypal / paypal-checkout-components / src / api / rest.js View on Github external
if (body && body.id) {
            return body.id;
        }

        throw new Error(`Order Api response error:\n\n${ JSON.stringify(body, null, 4) }`);
    });
}

const PROXY_REST = `proxy_rest`;
const parentWin = getAncestor();

on(PROXY_REST, { domain: getPayPalDomain() }, ({ data }) => {
    proxyRest = data;
});

if (parentWin && isPayPalDomain() && !isSameDomain(parentWin)) {
    send(parentWin, PROXY_REST, { createAccessToken, createOrder })
        .catch(() => {
            // pass
        });
}
github krakenjs / zoid / src / parent / index.js View on Github external
getPropsForChild(domain : string | RegExp) : (PropsType<p>) {
        const result = {};

        for (const key of Object.keys(this.props)) {
            const prop = this.component.getPropDefinition(key);

            if (prop &amp;&amp; prop.sendToChild === false) {
                continue;
            }

            if (prop &amp;&amp; prop.sameDomain &amp;&amp; !matchDomain(domain, getDomain(window))) {
                continue;
            }
            
            result[key] = this.props[key];
        }

        // $FlowFixMe
        return result;
    }
</p>