Do not fail when trying to find DE window with cross origin (#231)
* Do not fail when trying to find DE window with cross origin * Fix lint errors
This commit is contained in:
parent
dcc2036793
commit
70c7d84bdb
|
@ -49,17 +49,16 @@ export function sendCachedDataMessage<TResponseDataModel>(
|
|||
|
||||
export function sendMessage(data: any): void {
|
||||
if (canSendMessage()) {
|
||||
const dataExplorerWindow = getDataExplorerWindow(window);
|
||||
if (dataExplorerWindow) {
|
||||
dataExplorerWindow.parent.postMessage(
|
||||
// We try to find data explorer window first, then fallback to current window
|
||||
const portalChildWindow = getDataExplorerWindow(window) || window;
|
||||
portalChildWindow.parent.postMessage(
|
||||
{
|
||||
signature: "pcIframe",
|
||||
data: data
|
||||
},
|
||||
dataExplorerWindow.document.referrer
|
||||
portalChildWindow.document.referrer
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function canSendMessage(): boolean {
|
||||
|
|
|
@ -2,6 +2,8 @@ export const getDataExplorerWindow = (currentWindow: Window): Window | undefined
|
|||
// Start with the current window and traverse up the parent hierarchy to find a window
|
||||
// with `dataExplorerPlatform` property
|
||||
let dataExplorerWindow: Window | undefined = currentWindow;
|
||||
|
||||
try {
|
||||
// TODO: Need to `any` here since the window imports Explorer which can't be in strict mode yet
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
while (dataExplorerWindow && (dataExplorerWindow as any).dataExplorerPlatform === undefined) {
|
||||
|
@ -12,6 +14,10 @@ export const getDataExplorerWindow = (currentWindow: Window): Window | undefined
|
|||
dataExplorerWindow = dataExplorerWindow.parent;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// This can happen if we come across parent from a different origin
|
||||
dataExplorerWindow = undefined;
|
||||
}
|
||||
|
||||
return dataExplorerWindow;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue