Skip to content

Commit

Permalink
replay-web-page embed: emit 'rwp-page-loading' and 'rwp-url-change' c…
Browse files Browse the repository at this point in the history
…ustom events in response to window message

from internal iframe
  • Loading branch information
ikreymer committed Jun 19, 2024
1 parent 2eee5b6 commit 61e3854
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import { wrapCss, updateFaviconLinks } from "./misc";
import { SWManager } from "./swmanager";
import { property } from "lit/decorators.js";
import type { FavIconEventDetail } from "./types";
import type { EmbedReplayData } from "./item";
import type { EmbedReplayData, EmbedReplayEvent } from "./item";

type IframeMessage = MessageEvent<
| ({
type: "urlchange";
} & EmbedReplayData)
| EmbedReplayEvent
| ({
type: "favicons";
} & FavIconEventDetail)
| { loading: boolean; type: "page-loading" }
>;

const scriptSrc =
Expand Down Expand Up @@ -136,6 +135,19 @@ class Embed extends LitElement {
if (this.deepLink) {
this.handleUrlChangeMessage(event.data);
}
this.dispatchEvent(
new CustomEvent<EmbedReplayEvent>("rwp-url-change", {
detail: event.data,
}),
);
break;

case "page-loading":
this.dispatchEvent(
new CustomEvent<{ loading: boolean }>("rwp-page-loading", {
detail: event.data,
}),
);
break;

case "favicons":
Expand Down
7 changes: 6 additions & 1 deletion src/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export type EmbedReplayData = {
query?: string;
};

export type EmbedReplayEvent = EmbedReplayData & {
type: "urlchange";
replayNotFoundError: boolean;
};

export type TabData = EmbedReplayData & {
multiTs?: string[];
currList?: number;
Expand Down Expand Up @@ -349,7 +354,7 @@ class Item extends LitElement {
lastUpdate.query !== query ||
lastUpdate.title !== title
) {
const newUpdate = {
const newUpdate: EmbedReplayEvent = {
type: "urlchange",
url,
ts,
Expand Down

0 comments on commit 61e3854

Please sign in to comment.