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>
This commit is contained in:
Jan-Philipp Benecke 2025-03-14 13:45:22 +01:00 committed by GitHub
parent 91e9836423
commit 49b1198cb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -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`
<ha-card .header=${this._config.title}>
@ -104,7 +107,7 @@ export class HuiIframeCard extends LitElement implements LovelaceCard {
<iframe
title=${ifDefined(this._config.title)}
src=${this._config.url}
.sandbox=${`${sandbox_user_params} ${IFRAME_SANDBOX}`}
sandbox=${ifDefined(sandbox_params)}
allow=${this._config.allow ?? "fullscreen"}
></iframe>
</div>

View File

@ -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;