summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/portals/resources/predecessor-fires-unload-watch-unload.html
blob: f58da48ca1c78ffd22b86846484d011ac1133bb9 (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
<!DOCTYPE html>
<body>
<script>
function nextEvent(target, type) {
  return new Promise((resolve, reject) => target.addEventListener(type, e => resolve(e), {once: true}));
}

onload = async function() {
  const portal = document.createElement('portal');
  portal.src = new URL('simple-portal.html', location.href);
  document.body.appendChild(portal);
  await nextEvent(portal, 'load');

  let firedEvents = [];
  for (let type of ['pagehide', 'unload']) {
    nextEvent(window, type).then(() => {
      firedEvents.push(type);
      localStorage.setItem('predecessor-fires-unload-events', firedEvents.join(' '));
    });
  }

  portal.activate();
};
</script>
</body>