mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-02-16 17:25:58 +00:00
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,16 +49,15 @@ export function sendCachedDataMessage<TResponseDataModel>(
|
|||||||
|
|
||||||
export function sendMessage(data: any): void {
|
export function sendMessage(data: any): void {
|
||||||
if (canSendMessage()) {
|
if (canSendMessage()) {
|
||||||
const dataExplorerWindow = getDataExplorerWindow(window);
|
// We try to find data explorer window first, then fallback to current window
|
||||||
if (dataExplorerWindow) {
|
const portalChildWindow = getDataExplorerWindow(window) || window;
|
||||||
dataExplorerWindow.parent.postMessage(
|
portalChildWindow.parent.postMessage(
|
||||||
{
|
{
|
||||||
signature: "pcIframe",
|
signature: "pcIframe",
|
||||||
data: data
|
data: data
|
||||||
},
|
},
|
||||||
dataExplorerWindow.document.referrer
|
portalChildWindow.document.referrer
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,15 +2,21 @@ export const getDataExplorerWindow = (currentWindow: Window): Window | undefined
|
|||||||
// Start with the current window and traverse up the parent hierarchy to find a window
|
// Start with the current window and traverse up the parent hierarchy to find a window
|
||||||
// with `dataExplorerPlatform` property
|
// with `dataExplorerPlatform` property
|
||||||
let dataExplorerWindow: Window | undefined = currentWindow;
|
let dataExplorerWindow: Window | undefined = currentWindow;
|
||||||
// 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
|
try {
|
||||||
while (dataExplorerWindow && (dataExplorerWindow as any).dataExplorerPlatform === undefined) {
|
// TODO: Need to `any` here since the window imports Explorer which can't be in strict mode yet
|
||||||
// If a window does not have a parent, its parent property is a reference to itself.
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
if (dataExplorerWindow.parent === dataExplorerWindow) {
|
while (dataExplorerWindow && (dataExplorerWindow as any).dataExplorerPlatform === undefined) {
|
||||||
dataExplorerWindow = undefined;
|
// If a window does not have a parent, its parent property is a reference to itself.
|
||||||
} else {
|
if (dataExplorerWindow.parent === dataExplorerWindow) {
|
||||||
dataExplorerWindow = dataExplorerWindow.parent;
|
dataExplorerWindow = undefined;
|
||||||
|
} else {
|
||||||
|
dataExplorerWindow = dataExplorerWindow.parent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// This can happen if we come across parent from a different origin
|
||||||
|
dataExplorerWindow = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataExplorerWindow;
|
return dataExplorerWindow;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user