mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-06-30 02:28:44 +01:00
Fix getDataExplorerWindow (#285)
This commit is contained in:
+11
-16
@@ -1,23 +1,18 @@
|
||||
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;
|
||||
|
||||
// Data explorer is always loaded in an iframe, so traverse the parents until we hit the top and return the first child window.
|
||||
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) {
|
||||
// If a window does not have a parent, its parent property is a reference to itself.
|
||||
if (dataExplorerWindow.parent === dataExplorerWindow) {
|
||||
dataExplorerWindow = undefined;
|
||||
} else {
|
||||
dataExplorerWindow = dataExplorerWindow.parent;
|
||||
while (currentWindow) {
|
||||
if (currentWindow.parent === currentWindow) {
|
||||
return undefined;
|
||||
}
|
||||
if (currentWindow.parent === currentWindow.top) {
|
||||
return currentWindow;
|
||||
}
|
||||
currentWindow = currentWindow.parent;
|
||||
}
|
||||
} catch (error) {
|
||||
// This can happen if we come across parent from a different origin
|
||||
dataExplorerWindow = undefined;
|
||||
// Hitting a cross domain error means we are in the portal and the current window is data explorer
|
||||
return currentWindow;
|
||||
}
|
||||
|
||||
return dataExplorerWindow;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user