testing/web-platform/tests/html/browsers/the-window-object/apis-for-creating-and-navigating-browsing-contexts-by-name/resources/message-opener.html
author Gijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 12 Sep 2018 12:23:51 +0000
changeset 436046 8675ff71202cb14c8ff3d7138d8166ff5870b5cb
parent 357850 1ee09646e328f0d43feb567f209ab99f123776af
child 443846 29ebdc54d6bc82f8e5696f5129feffe2929460f3
permissions -rw-r--r--
Bug 1489700 - allow window positioning to be asynchronous, r=jgraham Differential Revision: https://phabricator.services.mozilla.com/D5666

<script src="/common/PrefixedPostMessage.js"></script>
<script>
var prefixedMessage = new PrefixedMessageResource();
var max = 50, attempts = 0;
function sendCoordinates() {
  // Certain windowing systems position windows asynchronously.
  // As a result, the window may not be positioned yet when the
  // load event fires. To accommodate this, allow waiting up to
  // 5 seconds for positioning to take place.
  if (!window.screenX && !window.screenY && ++attempts < max) {
    setTimeout(sendCoordinates, 100);
    return;
  }
  prefixedMessage.postToOpener({
    left: window.screenX,
    top: window.screenY,
    width: window.innerWidth,
    height: window.innerHeight
  });
}
window.addEventListener('load', sendCoordinates);
</script>