MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / useIframeDetection

Function useIframeDetection

frontend/src/hooks/useIframeDetection.ts:7–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5 * Hook to detect and handle iframe context
6 */
7export 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}

Callers 1

useHomePageLogicFunction · 0.90

Calls 1

detectIframeFunction · 0.70

Tested by

no test coverage detected