Skip to content

Commit

Permalink
feat: cleanup enclave iframe on reinitialisation (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Mamoun98 authored Dec 5, 2024
1 parent c6f6603 commit aeda550
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/idos-sdk-js/src/lib/enclave-providers/iframe-enclave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ export class IframeEnclave implements EnclaveProvider {
}) as Promise<idOSCredential[]>;
}

async #loadEnclave() {
const hasIframe = document.getElementById(this.iframe.id);
if (hasIframe) {
async #loadEnclave(): Promise<unknown> {
const container = document.querySelector(this.container);
const iframeElem = document.getElementById(this.iframe.id);

if (iframeElem) {
console.warn("An Iframe already exists in the container");
return Promise.resolve();
container?.removeChild(iframeElem);
return new Promise((resolve) => this.#loadEnclave().then(resolve));
}

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy#directives
Expand Down Expand Up @@ -149,7 +152,6 @@ export class IframeEnclave implements EnclaveProvider {
this.iframe.style.setProperty(k, v);
}

const container = document.querySelector(this.container);
if (!container) throw new Error(`Can't find container with selector ${this.container}`);

container.appendChild(this.iframe);
Expand Down

0 comments on commit aeda550

Please sign in to comment.