tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

message-opener.html (1955B)


      1 <script src="/common/PrefixedPostMessage.js"></script>
      2 <script>
      3 var prefixedMessage = new PrefixedMessageResource();
      4 var max = 150, attempts = 0;
      5 
      6 const urlParams = new URLSearchParams(location.search);
      7 const expected_innerWidth = urlParams.get('expected_innerWidth');
      8 const expected_innerHeight = urlParams.get('expected_innerHeight');
      9 const expected_screenX = urlParams.get('expected_screenX');
     10 const expected_screenY = urlParams.get('expected_screenY');
     11 let should_wait_until_settled = expected_innerWidth === null && expected_innerHeight === null && expected_screenX === null && expected_screenY === null;
     12 
     13 function sendCoordinates() {
     14  // Certain windowing systems position windows asynchronously.
     15  // As a result, the window may not be positioned yet when the
     16  // load event fires. To accommodate this, allow waiting up to
     17  // 15 seconds for positioning to take place.
     18  if ((!window.screenX && expected_screenX) &&
     19    (!window.screenY && expected_screenY) && ++attempts < max) {
     20    setTimeout(sendCoordinates, 100);
     21    return;
     22  }
     23  if (expected_innerWidth && window.innerWidth != expected_innerWidth && ++attempts < max) {
     24    setTimeout(sendCoordinates, 10);
     25    return;
     26  }
     27  if (expected_innerHeight && window.innerHeight != expected_innerHeight && ++attempts < max) {
     28    setTimeout(sendCoordinates, 10);
     29    return;
     30  }
     31  if (expected_screenX && window.screenX != expected_screenX && ++attempts < max) {
     32    setTimeout(sendCoordinates, 10);
     33    return;
     34  }
     35  if (expected_screenY && window.screenY != expected_screenY && ++attempts < max) {
     36    setTimeout(sendCoordinates, 10);
     37    return;
     38  }
     39  if (should_wait_until_settled) {
     40    should_wait_until_settled = false;
     41    setTimeout(sendCoordinates, 300);
     42    return;
     43  }
     44  prefixedMessage.postToOpener({
     45    left: window.screenX,
     46    top: window.screenY,
     47    width: window.innerWidth,
     48    height: window.innerHeight
     49  });
     50 }
     51 window.addEventListener('load', sendCoordinates);
     52 </script>