tor-browser

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

doc_network-observer.html (1571B)


      1 <!-- Any copyright is dedicated to the Public Domain.
      2     http://creativecommons.org/publicdomain/zero/1.0/ -->
      3 <!doctype html>
      4 
      5 <html>
      6  <head>
      7    <meta charset="utf-8"/>
      8    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
      9    <meta http-equiv="Pragma" content="no-cache" />
     10    <meta http-equiv="Expires" content="0" />
     11    <title>Network Observer test page</title>
     12  </head>
     13  <body>
     14    <p>Network Observer test page</p>
     15    <script type="text/javascript">
     16      /* exported registerServiceWorker, unregisterServiceWorker */
     17      "use strict";
     18 
     19        let swRegistration;
     20 
     21        function registerServiceWorker() {
     22          const sw = navigator.serviceWorker;
     23          return sw.register("serviceworker.js")
     24            .then(registration => {
     25              swRegistration = registration;
     26              console.log("Registered, scope is:", registration.scope);
     27              return sw.ready;
     28            }).then(() => {
     29              // wait until the page is controlled
     30              return new Promise(resolve => {
     31                if (sw.controller) {
     32                  resolve();
     33                } else {
     34                  sw.addEventListener("controllerchange", function () {
     35                    resolve();
     36                  }, { once: true });
     37                }
     38              });
     39            }).catch(() => {
     40              console.error("Registration failed");
     41            });
     42        }
     43 
     44        function unregisterServiceWorker() {
     45          return swRegistration.unregister();
     46        }
     47    </script>
     48  </body>
     49 </html>