 <iframe id="iframe2" src="resources/dialog-prevents-close.html"></iframe>

  <script>
    function awaitEvent(el, type, signal) {
      return new Promise((resolve) =>
        el.addEventListener(type, resolve, { once: true, signal }),
      );
    }

    async function iframeDialogIsOpen(iframe, signal) {
      const reply = awaitEvent(window, "message", signal);
      iframe.contentWindow.postMessage("dialog_open", "*");
      const {data} = (await reply);
      if (data.error) throw new Error(data.error