How to use the cross-domain-utils/src.isSameDomain function in cross-domain-utils

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 / 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 / component / parent / index.js View on Github external
getPropsRef(proxyWin : ProxyWindow, target : CrossDomainWindowType, domain : string | RegExp, uid : string) : PropRef {
        let value = serializeMessage(proxyWin, domain, this.getPropsForChild(domain));

        let propRef = isSameDomain(target)
            ? { type: INITIAL_PROPS.RAW, value }
            : { type: INITIAL_PROPS.UID, uid };

        if (propRef.type === INITIAL_PROPS.UID) {
            global.props[uid] = value;

            this.clean.register(() => {
                delete global.props[uid];
            });
        }

        return propRef;
    }
github krakenjs / zoid / src / lib / global.js View on Github external
export function getGlobal(win? : CrossDomainWindowType = window) : Object {

    if (!isSameDomain(win)) {
        throw new Error(`Can not get global for window on different domain`);
    }

    if (!win[__ZOID__.__GLOBAL_KEY__]) {
        win[__ZOID__.__GLOBAL_KEY__] = {};
    }

    return win[__ZOID__.__GLOBAL_KEY__];
}
github krakenjs / zoid / src / child / index.js View on Github external
if (type === WINDOW_REFERENCES.OPENER) {
            return assertExists('opener', getOpener(window));
    
        } else if (type === WINDOW_REFERENCES.PARENT && typeof ref.distance === 'number') {
            return assertExists('parent', getNthParentFromTop(window, ref.distance));

        } else if (type === WINDOW_REFERENCES.GLOBAL && ref.uid && typeof ref.uid === 'string') {
            const { uid } = ref;
            const ancestor = getAncestor(window);

            if (!ancestor) {
                throw new Error(`Can not find ancestor window`);
            }

            for (const frame of getAllFramesInWindow(ancestor)) {
                if (isSameDomain(frame)) {
                    const global = getGlobal(frame);

                    if (global && global.windows && global.windows[uid]) {
                        return global.windows[uid];
                    }
                }
            }
        }
    
        throw new Error(`Unable to find ${ type } parent component window`);
    }