Fix iframes in Safari PWA

pull/532/head
Zef Hemel 2023-10-09 21:02:57 +02:00
parent 17ba536801
commit dc255c3dda
2 changed files with 7 additions and 2 deletions

View File

@ -23,8 +23,10 @@ async function init() {
try { try {
const result = await syscall("widget.render", lang, body); const result = await syscall("widget.render", lang, body);
const iframe = document.createElement("iframe"); const iframe = document.createElement("iframe");
iframe.srcdoc = panelHtml; // set as a global iframe.src = "about:blank";
iframe.onload = () => { iframe.onload = () => {
iframe.contentDocument.write(panelHtml);
iframe.contentWindow.postMessage({ iframe.contentWindow.postMessage({
type: "html", type: "html",
theme: document.getElementsByTagName("html")[0].getAttribute( theme: document.getElementsByTagName("html")[0].getAttribute(

View File

@ -9,7 +9,7 @@ export function createWidgetSandboxIFrame(
onMessage?: (message: any) => void, onMessage?: (message: any) => void,
) { ) {
const iframe = document.createElement("iframe"); const iframe = document.createElement("iframe");
iframe.srcdoc = panelHtml; iframe.src = "about:blank";
const messageListener = (evt: any) => { const messageListener = (evt: any) => {
(async () => { (async () => {
@ -67,6 +67,9 @@ export function createWidgetSandboxIFrame(
}; };
iframe.onload = () => { iframe.onload = () => {
iframe.contentDocument!.write(panelHtml);
// return;
// Subscribe to message event on global object (to receive messages from iframe) // Subscribe to message event on global object (to receive messages from iframe)
globalThis.addEventListener("message", messageListener); globalThis.addEventListener("message", messageListener);
// Only run this code once // Only run this code once