Skip to content

Commit 3698084

Browse files
committed
simplify
1 parent d89340f commit 3698084

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

web/src/utils/isIFrame.ts

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
export const isInIframe = (() => {
22
try {
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;
3+
return window.self !== window.top;
224
} catch (e) {
23-
// If security error occurs when checking iframe, we're definitely in a cross-origin iframe
5+
// If we get a security error, we're definitely in an iframe
246
return true;
257
}
268
})();

0 commit comments

Comments
 (0)