<!DOCTYPE html>
<body>
  <script>
    var portal1 = document.createElement("portal");
    portal1.src = "simple-portal.html"
    var portal2 = document.createElement("portal");
    portal2.src = "simple-portal.html"

    var waitForPortalToLoad = portal => new Promise((resolve, reject) => {
      portal.onload = resolve;
    });

    Promise.all([waitForPortalToLoad(portal1),
                 waitForPortalToLoad(portal2)]).then(() => {
      portal1.activate();
      portal2.activate().catch(e => window.opener.postMessage(e.name, "*"));
    });

    document.body.append(portal1);
    document.body.append(portal2);
  </script>
</body>
