-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathha-panel-iframe.ts
More file actions
66 lines (59 loc) · 1.76 KB
/
ha-panel-iframe.ts
File metadata and controls
66 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { html, css, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import "../../layouts/hass-error-screen";
import "../../layouts/hass-subpage";
import type { HomeAssistant, PanelInfo } from "../../types";
import { IFRAME_SANDBOX_SAME_ORIGIN } from "../../util/iframe";
@customElement("ha-panel-iframe")
class HaPanelIframe extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean }) public narrow = false;
@property({ attribute: false }) panel!: PanelInfo<{ url: string }>;
render() {
if (
location.protocol === "https:" &&
new URL(this.panel.config.url, location.toString()).protocol !== "https:"
) {
return html`
<hass-error-screen
.hass=${this.hass}
.narrow=${this.narrow}
error="Unable to load iframes that load websites over http:// if Home Assistant is served over https://."
rootnav
></hass-error-screen>
`;
}
return html`
<hass-subpage
.hass=${this.hass}
.narrow=${this.narrow}
.header=${this.panel.title}
main-page
>
<iframe
title=${ifDefined(
this.panel.title === null ? undefined : this.panel.title
)}
src=${this.panel.config.url}
.sandbox=${IFRAME_SANDBOX_SAME_ORIGIN}
allow="fullscreen"
></iframe>
</hass-subpage>
`;
}
static styles = css`
iframe {
border: 0;
width: 100%;
position: absolute;
height: 100%;
background-color: var(--primary-background-color);
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-panel-iframe": HaPanelIframe;
}
}