<!DOCTYPE html>
<body>
  <script>
    var portal = document.createElement("portal");
    portal.src = "portal-post-message-portal.html";
    document.body.appendChild(portal);

    portal.onload = () => {
      portal.activate().then(() => {
        error = "";
        try {
          portal.postMessage("message");
        }
        catch(err) {
          error = err.name;
        }
        bc = new BroadcastChannel("portals-post-message-after-activate");
        bc.postMessage(error);
        bc.close();
      });
    }
  </script>
</body>
