<!DOCTYPE html>
<script>
  var postMessagePromise = new Promise((resolve, reject) => {
    window.portalHost.addEventListener("message", () => {
      resolve(performance.now());
    });
  });

  var activatePromise = new Promise((resolve, reject) => {
    window.onportalactivate = () => {
      resolve(performance.now());
    }
  });

  Promise.all([postMessagePromise, activatePromise])
    .then(values => {
      bc = new BroadcastChannel("portals-post-message-before-activate");
      bc.postMessage({
        postMessageTS: values[0],
        activateTS: values[1]
      });
      bc.close();
    });
</script>
