Skip to content

Commit 3f51f35

Browse files
committed
embeds: add automatic reload if serivceWorker is available but controller is not to catch any race condition where serviceWorker has not yet been activated
1 parent 8737319 commit 3f51f35

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "replaywebpage",
33
"productName": "ReplayWeb.page",
4-
"version": "1.0.2-dev.0",
4+
"version": "1.0.2",
55
"description": "Serverless Web Archive Replay",
66
"repository": "https://github.com/webrecorder/replayweb.page",
77
"homepage": "https://replayweb.page/",

src/embed.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,22 @@ Please try a different browser.\n
183183
if (this.injected) {
184184
return;
185185
}
186-
if (event.target.contentWindow.customElements.get("replay-app-main")) {
186+
const win = event.target.contentWindow;
187+
const doc = event.target.contentDocument;
188+
189+
if (win.navigator.serviceWorker && !win.navigator.serviceWorker.controller) {
190+
setTimeout(() => window.location.reload(), 100);
187191
return;
188192
}
189-
const script = event.target.contentDocument.createElement("script");
193+
194+
if (win.customElements.get("replay-app-main")) {
195+
return;
196+
}
197+
198+
const script = doc.createElement("script");
190199
//const script = event.target.contentDocument.querySelector("script");
191200
script.src = scriptSrc;
192-
event.target.contentDocument.head.appendChild(script);
201+
doc.head.appendChild(script);
193202
this.injected = true;
194203
}
195204
}

0 commit comments

Comments
 (0)