embeds: add automatic reload if serivceWorker is available but controller is not to catch any race condition where serviceWorker has not yet been activated

This commit is contained in:
Ilya Kreymer
2020-07-27 17:29:58 -07:00
parent 8737319b5b
commit 3f51f35b9f
3 changed files with 16 additions and 7 deletions
+12 -3
View File
@@ -183,13 +183,22 @@ Please try a different browser.\n
if (this.injected) {
return;
}
if (event.target.contentWindow.customElements.get("replay-app-main")) {
const win = event.target.contentWindow;
const doc = event.target.contentDocument;
if (win.navigator.serviceWorker && !win.navigator.serviceWorker.controller) {
setTimeout(() => window.location.reload(), 100);
return;
}
const script = event.target.contentDocument.createElement("script");
if (win.customElements.get("replay-app-main")) {
return;
}
const script = doc.createElement("script");
//const script = event.target.contentDocument.querySelector("script");
script.src = scriptSrc;
event.target.contentDocument.head.appendChild(script);
doc.head.appendChild(script);
this.injected = true;
}
}