Skip to content

Commit

Permalink
add check for contentWindow & contentWindow.postMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
turnekybc committed Dec 19, 2024
1 parent 4139ebb commit 8e0c1eb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/iframe-stamper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ export class IframeStamper {
* See https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage#transfer
*/
this.iframe.addEventListener("load", () => {
this.iframe.contentWindow?.postMessage(
if (!this.iframe.contentWindow || !this.iframe.contentWindow.postMessage) {
throw new Error(
"contentWindow or contentWindow.postMessage does not exist"
);
}

this.iframe.contentWindow.postMessage(
{ type: IframeEventType.TurnkeyInitMessageChannel },
this.iframeOrigin,
[this.messageChannel.port2]
Expand Down

0 comments on commit 8e0c1eb

Please sign in to comment.