From 49b1198cb7e44048b121959b1aa9b4806eb97103 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Fri, 14 Mar 2025 13:45:22 +0100 Subject: [PATCH] Add yaml option to disable iFrame sandbox to embed PDFs (#24620) * Add yaml option to disable iFrame sandbox to embed PDFs * Apply suggestions from code review Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com> --------- Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com> --- src/panels/lovelace/cards/hui-iframe-card.ts | 7 +++++-- src/panels/lovelace/cards/types.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/cards/hui-iframe-card.ts b/src/panels/lovelace/cards/hui-iframe-card.ts index 7438372335..63955f93dc 100644 --- a/src/panels/lovelace/cards/hui-iframe-card.ts +++ b/src/panels/lovelace/cards/hui-iframe-card.ts @@ -6,13 +6,13 @@ import parseAspectRatio from "../../../common/util/parse-aspect-ratio"; import "../../../components/ha-alert"; import "../../../components/ha-card"; import type { HomeAssistant } from "../../../types"; -import { IFRAME_SANDBOX } from "../../../util/iframe"; import type { LovelaceCard, LovelaceCardEditor, LovelaceGridOptions, } from "../types"; import type { IframeCardConfig } from "./types"; +import { IFRAME_SANDBOX } from "../../../util/iframe"; @customElement("hui-iframe-card") export class HuiIframeCard extends LitElement implements LovelaceCard { @@ -92,6 +92,9 @@ export class HuiIframeCard extends LitElement implements LovelaceCard { if (this._config.allow_open_top_navigation) { sandbox_user_params += "allow-top-navigation-by-user-activation"; } + const sandbox_params = this._config.disable_sandbox + ? undefined + : `${sandbox_user_params} ${IFRAME_SANDBOX}`; return html` @@ -104,7 +107,7 @@ export class HuiIframeCard extends LitElement implements LovelaceCard { diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index ef6a20f31b..cd3266e908 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -286,6 +286,7 @@ export interface HumidifierCardConfig extends LovelaceCardConfig { export interface IframeCardConfig extends LovelaceCardConfig { allow_open_top_navigation?: boolean; aspect_ratio?: string; + disable_sandbox?: boolean; title?: string; allow?: string; url: string;