tor-browser

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

notification-on-activation.html (1395B)


      1 <!DOCTYPE html>
      2 <script src="utils.js"></script>
      3 <script>
      4 
      5 const params = new URLSearchParams(location.search);
      6 
      7 // The main test page (restriction-notification.https.html) loads the initiator
      8 // page, then the initiator page will prerender itself with the `prerendering`
      9 // parameter.
     10 const isPrerendering = params.has('prerendering');
     11 
     12 if (!isPrerendering) {
     13  loadInitiatorPage();
     14 } else {
     15  // Used to communicate with the initiator page.
     16  const prerenderChannel = new PrerenderChannel('prerender-channel');
     17  // Used to communicate with the main test page.
     18  const testChannel = new PrerenderChannel('test-channel');
     19 
     20  window.addEventListener('load', () => {
     21    // Inform the initiator page that this page is ready to be activated.
     22    prerenderChannel.postMessage('readyToActivate');
     23    prerenderChannel.close();
     24  });
     25 
     26  document.addEventListener('prerenderingchange', () => {
     27    // Accessing the Notification API is allowed after the prerendering state
     28    // changed.
     29    const permission = Notification.permission;
     30    const notification = new Notification('New Notification');
     31 
     32    notification.onerror = function(_) {
     33      testChannel.postMessage('notification error');
     34      testChannel.close();
     35    }
     36    notification.onshow = function() {
     37      testChannel.postMessage('notification showed');
     38      notification.close();
     39      testChannel.close();
     40    };
     41  });
     42 }
     43 
     44 </script>