"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const iframeSrc = `https://www.unpkg.com/@meteor-web3/meteor-iframe@latest/dist/index.html`;
function injectIframe() {
    if (window.__METEOR_IFRAME_INJECTED__ ||
        document.getElementById("meteor-iframe") !== null) {
        console.info("Meteor iframe already injected.");
        return;
    }
    const iframe = document.createElement("iframe");
    iframe.id = "meteor-iframe";
    iframe.src = iframeSrc;
    iframe.style.width = "0";
    iframe.style.height = "0";
    iframe.style.display = "none";
    document.body.appendChild(iframe);
    window.__METEOR_IFRAME_INJECTED__ = true;
    const iframeListener = (event) => {
        if (event.source === iframe.contentWindow &&
            event.data.type === "METEOR_IFRAME_READY") {
            window.__METEOR_IFRAME_READY__ = true;
            console.info("Meteor iframe ready.");
            window.removeEventListener("message", iframeListener);
        }
    };
    window.addEventListener("message", iframeListener);
    // iframe.onload = () => {
    //   (window as any).__METEOR_IFRAME_READY__ = true;
    //   console.info("Meteor iframe ready.");
    // };
}
if (document.readyState === "complete") {
    injectIframe();
}
else {
    document.addEventListener("readystatechange", () => {
        if (document.readyState === "complete") {
            injectIframe();
        }
    });
}
