Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify #46

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions web/src/utils/isIFrame.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
export const isInIframe = (() => {
try {
// Check if in iframe
const isInIframe = window.self !== window.top;

if (!isInIframe) return true;

// Check for Home Assistant specific objects or elements
const hasHAElements =
// Check if Home Assistant custom elements exist in parent document
window.parent?.customElements?.get("home-assistant") !== undefined ||
// Check URL for typical Home Assistant paths
window.location.href.includes("/api/hassio") ||
// Check for typical Home Assistant URL patterns in referrer
document.referrer.includes("homeassistant") ||
document.referrer.includes("/api/hassio_ingress/") ||
// Check parent URL if accessible
window.parent?.location?.href?.includes("homeassistant") ||
false;

return hasHAElements;
return window.self !== window.top;
} catch (e) {
// If security error occurs when checking iframe, we're definitely in a cross-origin iframe
// If we get a security error, we're definitely in an iframe
return true;
}
})();