tor-browser

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

getusermedia_xorigin_iframe.html (1003B)


      1 <html>
      2  <head>
      3    <meta charset="utf-8" />
      4    <title>GetUserMedia from cross-origin iframe: the iframe document</title>
      5  </head>
      6  <body>
      7    <script>
      8      "use strict";
      9 
     10      let stream;
     11      window.addEventListener(
     12        "message",
     13        async ({ data: { name, gen, constraints } }) => {
     14          if (name == "start") {
     15            try {
     16              stream = await navigator.mediaDevices.getUserMedia(constraints);
     17              Send({ gen, result: "ok" });
     18            } catch (e) {
     19              Send({ gen, result: `${e}` });
     20            }
     21          } else if (name == "stop") {
     22            const result = !!stream;
     23            if (stream) {
     24              for (const t of stream.getTracks()) {
     25                t.stop();
     26              }
     27              stream = undefined;
     28            }
     29            Send({ gen, result });
     30          }
     31        }
     32      );
     33 
     34      function Send(obj) {
     35        window.parent.postMessage(obj, "http://localhost:4245");
     36      }
     37    </script>
     38  </body>
     39 </html>