export default class IframeReference { private static targetOrigin: string | null = null; private static iframe: HTMLIFrameElement | null = null; private constructor() { } public static setTargetOrigin(targetOrigin: string): void { if (this.targetOrigin) { console.debug("targetOrigin is already set"); return; } try { new URL(targetOrigin); this.targetOrigin = targetOrigin; } catch { throw new Error(`Invalid targetOrigin: ${targetOrigin}`); } } public static getTargetOrigin(): string { if (!this.targetOrigin) { throw new Error("targetOrigin is not set"); } return this.targetOrigin; } public static setIframe(iframe: HTMLIFrameElement | null): void { if (iframe !== null && !(iframe instanceof HTMLIFrameElement)) { throw new Error("setIframe expects an HTMLIFrameElement or null"); } this.iframe = iframe; } public static getIframe(): HTMLIFrameElement { if (!this.iframe) { throw new Error("iframe is not set"); } return this.iframe; } }