summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/portals/resources/portal-post-message-portal.html
blob: e83ae56e08fcb251577168ba8cc8dce0e3100133 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!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>