tor-browser

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

clients-get-cross-origin-frame.html (1578B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/common/get-host-info.sub.js"></script>
      5 <script src="test-helpers.sub.js"></script>
      6 <script>
      7 var host_info = get_host_info();
      8 var scope = 'blank.html?clients-get';
      9 var script = 'clients-get-worker.js';
     10 
     11 var registration;
     12 var worker;
     13 var wait_for_worker_promise = navigator.serviceWorker.getRegistration(scope)
     14  .then(function(reg) {
     15      if (reg)
     16        return reg.unregister();
     17    })
     18  .then(function() {
     19      return navigator.serviceWorker.register(script, {scope: scope});
     20    })
     21  .then(function(reg) {
     22      registration = reg;
     23      worker = reg.installing;
     24      return new Promise(function(resolve) {
     25          worker.addEventListener('statechange', function() {
     26              if (worker.state == 'activated')
     27                resolve();
     28            });
     29        });
     30    });
     31 
     32 window.addEventListener('message', function(e) {
     33  var cross_origin_client_ids = [];
     34  cross_origin_client_ids.push(e.data.clientId);
     35  wait_for_worker_promise
     36    .then(function() {
     37        return with_iframe(scope);
     38      })
     39    .then(function(iframe) {
     40        add_completion_callback(function() { iframe.remove(); });
     41        navigator.serviceWorker.onmessage = function(e) {
     42          registration.unregister();
     43          window.parent.postMessage(
     44            { type: 'clientId', value: e.data }, host_info['HTTPS_ORIGIN']
     45          );
     46        };
     47        registration.active.postMessage({clientIds: cross_origin_client_ids});
     48      });
     49 });
     50 </script>