From 8e0c1eb5d8663ab70e8584f318077e618c3595f3 Mon Sep 17 00:00:00 2001 From: Brian Cleary Date: Thu, 19 Dec 2024 14:22:18 -0500 Subject: [PATCH] add check for contentWindow & contentWindow.postMessage --- packages/iframe-stamper/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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]