UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

1 lines 1.53 kB
{"version":3,"file":"runtime.mjs","names":[],"sources":["../../../src/internal/clerk-js/runtime.ts"],"sourcesContent":["export function inBrowser() {\n return typeof globalThis.document !== 'undefined';\n}\n\nexport function inActiveBrowserTab() {\n return inBrowser() && globalThis.document.hasFocus();\n}\n\nexport function inIframe() {\n if (!inBrowser()) {\n return false;\n }\n\n try {\n // checks if the current window is an iframe\n return window.self !== window.top;\n } catch {\n // Cross-origin access denied - we're definitely in an iframe\n return true;\n }\n}\n\nexport function inCrossOriginIframe() {\n if (!inIframe()) {\n return false;\n }\n\n try {\n // Try to access top window's location to check if any ancestor is cross-origin\n // This will throw a SecurityError if any iframe in the chain is cross-origin\n // Handles nested iframes where immediate parent might be same-origin\n // but a higher-level ancestor is cross-origin\n void window.top?.location.href;\n return false;\n } catch {\n // SecurityError thrown - we're in a cross-origin iframe (at any level)\n return true;\n }\n}\n"],"mappings":";AAAA,SAAgB,YAAY;CAC1B,OAAO,OAAO,WAAW,aAAa;AACxC;AAEA,SAAgB,qBAAqB;CACnC,OAAO,UAAU,KAAK,WAAW,SAAS,SAAS;AACrD;AAEA,SAAgB,WAAW;CACzB,IAAI,CAAC,UAAU,GACb,OAAO;CAGT,IAAI;EAEF,OAAO,OAAO,SAAS,OAAO;CAChC,QAAQ;EAEN,OAAO;CACT;AACF;AAEA,SAAgB,sBAAsB;CACpC,IAAI,CAAC,SAAS,GACZ,OAAO;CAGT,IAAI;EAKF,AAAK,OAAO,KAAK,SAAS;EAC1B,OAAO;CACT,QAAQ;EAEN,OAAO;CACT;AACF"}