tor-browser

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

browser_cached_force_refresh.html (1580B)


      1 <!--
      2  Any copyright is dedicated to the Public Domain.
      3  http://creativecommons.org/publicdomain/zero/1.0/
      4 -->
      5 <!DOCTYPE HTML>
      6 <html>
      7 <head>
      8 </head>
      9 <body>
     10 <script type="text/javascript">
     11 function ok(exp, msg) {
     12  if (!exp) {
     13    throw(msg);
     14  }
     15 }
     16 
     17 function is(actual, expected, msg) {
     18  if (actual !== expected) {
     19    throw('got "' + actual + '", but expected "' + expected + '" - ' + msg);
     20  }
     21 }
     22 
     23 function fail(err) {
     24  window.dispatchEvent(new Event("cached-failure", { bubbles: true, detail: err }));
     25 }
     26 
     27 function getUncontrolledClients(sw) {
     28  return new Promise(function(resolve, reject) {
     29    navigator.serviceWorker.addEventListener('message', function onMsg(evt) {
     30      if (evt.data.type === 'CLIENTS') {
     31        navigator.serviceWorker.removeEventListener('message', onMsg);
     32        resolve(evt.data.detail);
     33      }
     34    });
     35    sw.postMessage({ type: 'GET_UNCONTROLLED_CLIENTS' })
     36  });
     37 }
     38 
     39 addEventListener('load', function(event) {
     40  if (!navigator.serviceWorker.controller) {
     41    fail(window.location.href + ' is not controlled!');
     42    return;
     43  }
     44 
     45  getUncontrolledClients(navigator.serviceWorker.controller)
     46    .then(function(clientList) {
     47      is(clientList.length, 1, 'should only have one client');
     48      is(clientList[0].url, window.location.href,
     49         'client url should match current window');
     50      is(clientList[0].frameType, 'top-level',
     51         'client should be a top-level window');
     52      window.dispatchEvent(new Event('cached-load', { bubbles: true }));
     53    })
     54    .catch(function(err) {
     55      fail(err);
     56    });
     57 });
     58 </script>
     59 </body>
     60 </html>