<!DOCTYPE html>
<script>
  window.portalHost.onmessage = e => {
    var message = {
      origin: e.origin,
      data: e.data,
      sourceIsPortalHost: e.source === window.portalHost,
      gotUserActivation: !!e.userActivation,
      userActivation: {
        isActive: e.userActivation && e.userActivation.isActive,
        hasBeenActive: e.userActivation && e.userActivation.hasBeenActive
      }
    };

    if (e.data.arrayBuffer) {
      message.data = {
        array: Array.from(new Uint8Array(e.data.arrayBuffer))
      };
    }

    if (e.ports.length > 0) {
      e.ports[0].postMessage(message);
      e.ports[0].close();
      return;
    }

    window.portalHost.postMessage(message);
  };
</script>
