Skip to content

Commit aa596a1

Browse files
authored
Merge pull request #44 from hawkeye217/iframe-fix
test for more HA elements
2 parents cf3c0b2 + ad31af5 commit aa596a1

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

web/src/utils/isIFrame.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
export const isInIframe = (() => {
22
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;
422
} 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
624
return true;
725
}
826
})();

0 commit comments

Comments
 (0)