File tree 1 file changed +20
-2
lines changed
1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1
1
export const isInIframe = ( ( ) => {
2
2
try {
3
- return window . self !== window . top ;
3
+ // Check if in iframe
4
+ const isInIframe = window . self !== window . top ;
5
+
6
+ if ( ! isInIframe ) return true ;
7
+
8
+ // Check for Home Assistant specific objects or elements
9
+ const hasHAElements =
10
+ // Check if Home Assistant custom elements exist in parent document
11
+ window . parent ?. customElements ?. get ( "home-assistant" ) !== undefined ||
12
+ // Check URL for typical Home Assistant paths
13
+ window . location . href . includes ( "/api/hassio" ) ||
14
+ // Check for typical Home Assistant URL patterns in referrer
15
+ document . referrer . includes ( "homeassistant" ) ||
16
+ document . referrer . includes ( "/api/hassio_ingress/" ) ||
17
+ // Check parent URL if accessible
18
+ window . parent ?. location ?. href ?. includes ( "homeassistant" ) ||
19
+ false ;
20
+
21
+ return hasHAElements ;
4
22
} catch ( e ) {
5
- // If we get a security error , we're definitely in an iframe
23
+ // If security error occurs when checking iframe , we're definitely in a cross-origin iframe
6
24
return true ;
7
25
}
8
26
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments