Skip to content

Commit

Permalink
allow passing postMessages from iframe or sw to parent
Browse files Browse the repository at this point in the history
bump to 2.2.0-beta.2, wabac.js 2.20.0-beta.3
  • Loading branch information
ikreymer committed Oct 11, 2024
1 parent 3fb1079 commit 59b107d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "replaywebpage",
"productName": "ReplayWeb.page",
"version": "2.2.0-beta.1",
"version": "2.2.0-beta.2",
"description": "Serverless Web Archive Replay",
"repository": "https://github.com/webrecorder/replayweb.page",
"homepage": "https://replayweb.page/",
Expand All @@ -18,7 +18,7 @@
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4",
"@shoelace-style/shoelace": "~2.15.1",
"@webrecorder/wabac": "^2.20.0-beta.2",
"@webrecorder/wabac": "^2.20.0-beta.3",
"bulma": "^0.9.3",
"electron-log": "^4.4.1",
"electron-updater": "^6.3.2",
Expand Down
21 changes: 15 additions & 6 deletions src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ class Replay extends LitElement {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/promise-function-async
navigator.serviceWorker.addEventListener("message", (event) =>
this.handleAuthMessage(event),
this.handleSWMessage(event),
);
}

// @ts-expect-error [// TODO: Fix this the next time the file is edited.] - TS7006 - Parameter 'event' implicitly has an 'any' type.
async handleAuthMessage(event) {
async handleSWMessage(event: MessageEvent) {
if (
event.data.type === "authneeded" &&
this.collInfo &&
Expand Down Expand Up @@ -90,6 +89,8 @@ class Replay extends LitElement {
} else {
this.showAuth = true;
}
} else if (event.data.type) {
window.parent.postMessage(event.data);
}
}

Expand Down Expand Up @@ -211,6 +212,10 @@ class Replay extends LitElement {
}
} else if (event.data.wb_type === "title") {
this.title = event.data.title;
} else {
const passEvent = { type: event.data.wb_type, ...event.data };
delete passEvent.wb_type;
window.parent.postMessage(passEvent);
}
}
}
Expand Down Expand Up @@ -272,9 +277,13 @@ class Replay extends LitElement {
}

if (iframeWin) {
iframeWin.addEventListener("beforeunload", () => {
this.setLoading();
});
try {
iframeWin.addEventListener("beforeunload", () => {
this.setLoading();
});
} catch (e) {
// ignore
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1021,10 +1021,10 @@
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-2.0.5.tgz#325db42395cd49fe6c14057f9a900e427df8810e"
integrity sha512-lqaoKnRYBdo1UgDX8uF24AfGMifWK19TxPmM5FHc2vAGxrJ/qtyUyFBWoY1tISZdelsQ5fBcOusifo5o5wSJxQ==

"@webrecorder/wabac@^2.20.0-beta.2":
version "2.20.0-beta.2"
resolved "https://registry.yarnpkg.com/@webrecorder/wabac/-/wabac-2.20.0-beta.2.tgz#532b6457cb970039812e3b1470134725d7e72ca5"
integrity sha512-ENVlZOvnFpQO/iMDQX9IZzXrStqlKbDrXe5Tl1aEq0Diun+HI7RKZPF3jJjYEZr0GCON4yY8FNEZhodJCI7dGA==
"@webrecorder/wabac@^2.20.0-beta.3":
version "2.20.0-beta.3"
resolved "https://registry.yarnpkg.com/@webrecorder/wabac/-/wabac-2.20.0-beta.3.tgz#034cd07078270537028104ba407ae5b7baa2dd20"
integrity sha512-/s98zVZFn8+0btTwsb2kRiwyfLZxPyWwKclsrpFQvyUCsvrQsTTKVbHTpictAlmyknOIdkrLqqWK4ScYTs39Xg==
dependencies:
"@peculiar/asn1-ecc" "^2.3.4"
"@peculiar/asn1-schema" "^2.3.3"
Expand Down

0 comments on commit 59b107d

Please sign in to comment.