25 lines
790 B
TypeScript
25 lines
790 B
TypeScript
/**
|
|
* Whether the application is currently hosted by another page.
|
|
*
|
|
* This intentionally covers both a native `<iframe>` and Wujie's child-app
|
|
* runtime. Accessing `window.top` is safe across origins for identity
|
|
* comparison, but the guard keeps the login/route bootstrap resilient to
|
|
* restrictive browser hosts.
|
|
*/
|
|
export function isEmbeddedHost(): boolean {
|
|
if (typeof window === "undefined") return false;
|
|
|
|
const hostWindow = window as Window & {
|
|
__POWERED_BY_WUJIE__?: boolean;
|
|
};
|
|
if (hostWindow.__POWERED_BY_WUJIE__) return true;
|
|
|
|
try {
|
|
return window.self !== window.top;
|
|
} catch {
|
|
// Some sandboxed or cross-origin hosts deny top-window access. They are
|
|
// still embedded contexts and should use the same safe entry route.
|
|
return true;
|
|
}
|
|
}
|