gum inline iframe srcdoc

by jib1

HTML

<video id="video" width="160" height="120" controls autoplay></video>
<div id="div" style="white-space: pre;"></div>

JavaScript

let console = { log: msg => div.innerHTML += msg + "<br>" };
let wait = ms => new Promise(resolve => setTimeout(resolve, ms));

function iframeFunc(e) {
  window.parent.o1 = navigator.mediaDevices;
};

let p;

(async () => {
  try {
    let iframe = document.createElement("iframe");
    iframe.srcdoc = `\<html\>
\<script type='application/javascript'\>
(${iframeFunc.toString()})();\</script\>\</html\>`;

    document.documentElement.appendChild(iframe);
    await new Promise(r => iframe.onload = r);
    console.log(window.o1);
    iframe.contentWindow.location.href = "https://mozilla.github.io/webrtc-landing/gum_test.html";
    p = window.o1.getUserMedia({audio:true});
    video.srcObject = await p;
    console.log(video.srcObject);
  } catch (e) {
    console.log(e);
  }
})();