()
| 5 | * Hook to detect and handle iframe context |
| 6 | */ |
| 7 | export const useIframeDetection = () => { |
| 8 | const { setIsInIframe, setSidebarCollapsed } = useAppStore() |
| 9 | |
| 10 | useEffect(() => { |
| 11 | const detectIframe = () => { |
| 12 | try { |
| 13 | return window.self !== window.top |
| 14 | } catch (e) { |
| 15 | // If we can't access window.top due to cross-origin restrictions, |
| 16 | // we're likely in an iframe |
| 17 | return true |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | const isInIframe = detectIframe() |
| 22 | setIsInIframe(isInIframe) |
| 23 | |
| 24 | // If we're in an iframe, collapse the sidebar by default |
| 25 | if (isInIframe) { |
| 26 | setSidebarCollapsed(true) |
| 27 | } |
| 28 | }, [setIsInIframe, setSidebarCollapsed]) |
| 29 | } |
no test coverage detected