tor-browser

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

postMessage_override_helper.html (932B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <title>Overriding postMessage and dispatchEvent bindings</title>
      5  <script type="application/javascript">
      6    window.postMessage = function (evt) {
      7      window.parent.postMessage("FAIL overridden postMessage called", "*");
      8    };
      9 
     10    var count = 0;
     11 
     12    function receiveMessage(evt) {
     13      count++;
     14      if (count == 2) {
     15        window.dispatchEvent = function(evt) {
     16          window.parent.postMessage("FAIL", "*");
     17          throw "dispatchEvent threw";
     18        };
     19      }
     20 
     21      window.parent.postMessage(evt.data, "http://mochi.test:8888");
     22    }
     23 
     24    function setup() {
     25      var target = document.getElementById("location");
     26      target.textContent = location.hostname + ":" + (location.port || 80);
     27    }
     28 
     29    window.addEventListener("message", receiveMessage);
     30 
     31    window.addEventListener("load", setup);
     32  </script>
     33 </head>
     34 <body>
     35 <h1 id="location">No location!</h1>
     36 </body>
     37 </html>