Make chrome work-around work in iframes (#9200)

This commit is contained in:
Bram Kragten
2021-05-21 09:09:31 +02:00
committed by GitHub
parent 9328576b55
commit fd9bb4d8cc
10 changed files with 79 additions and 40 deletions

View File

@@ -1,4 +1,5 @@
import { HASSDomEvent, ValidHassDomEvent } from "../common/dom/fire_event";
import { mainWindow } from "../common/dom/get_main_window";
import { ProvideHassElement } from "../mixins/provide-hass-lit-mixin";
declare global {
@@ -67,25 +68,26 @@ export const showDialog = async (
}
if (addHistory) {
top.history.replaceState(
mainWindow.history.replaceState(
{
dialog: dialogTag,
open: false,
oldState:
top.history.state?.open && top.history.state?.dialog !== dialogTag
? top.history.state
mainWindow.history.state?.open &&
mainWindow.history.state?.dialog !== dialogTag
? mainWindow.history.state
: null,
},
""
);
try {
top.history.pushState(
mainWindow.history.pushState(
{ dialog: dialogTag, dialogParams: dialogParams, open: true },
""
);
} catch (err) {
// dialogParams could not be cloned, probably contains callback
top.history.pushState(
mainWindow.history.pushState(
{ dialog: dialogTag, dialogParams: null, open: true },
""
);
@@ -96,7 +98,10 @@ export const showDialog = async (
};
export const replaceDialog = () => {
top.history.replaceState({ ...top.history.state, replaced: true }, "");
mainWindow.history.replaceState(
{ ...mainWindow.history.state, replaced: true },
""
);
};
export const closeDialog = async (dialogTag: string): Promise<boolean> => {