tor-browser

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

postback.html (1487B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <script src="/common/dispatcher/dispatcher.js"></script>
      4 <script>
      5 const params = new URL(location).searchParams;
      6 const channelName = params.get("channel");
      7 const responseToken = params.get("responseToken");
      8 const iframeToken = params.get("iframeToken");
      9 
     10 // If the channel parameter is set, use the BroadcastChannel-based communication
     11 // method. Otherwise, use the dispatcher (useful in cases where this is embedded
     12 // in a third-party iframe that doesn't share a partition with the top-level
     13 // site).
     14 if (channelName != "null") {
     15  const bc = new BroadcastChannel(channelName);
     16  // Handle the close message from the test-cleanup, forwarding it to the
     17  // top level document, as this iframe and the opening document might not
     18  // be able to close the popup.
     19  bc.onmessage = event => {
     20    if (event.data == "close") {
     21       top.postMessage("close", "*");
     22     }
     23  };
     24 
     25  window.addEventListener("message", event => {
     26    bc.postMessage(event.data);
     27  });
     28 
     29 } else {
     30  window.addEventListener("message", event => {
     31    send(responseToken, JSON.stringify(event.data));
     32  });
     33 
     34  async function waitToClose() {
     35    response = await receive(iframeToken);
     36    // Handle the close message from the test-cleanup, forwarding it to the
     37    // top level document, as this iframe and the opening document might not
     38    // be able to close the popup.
     39    if (response == "close") {
     40      top.postMessage("close", "*");
     41    }
     42  }
     43  waitToClose();
     44 }
     45 </script>