diff --git a/packages/iframe-stamper/src/index.ts b/packages/iframe-stamper/src/index.ts index fead60c9..943c2ca5 100644 --- a/packages/iframe-stamper/src/index.ts +++ b/packages/iframe-stamper/src/index.ts @@ -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]