<body>
    <script>
function isFilteringEnabled()
{
    var pc = new RTCPeerConnection();
    pc.createDataChannel("");

    var candidates = [];
    return new Promise((resolve, reject) => {
        pc.onicecandidate = (event) => {
            if (event.candidate === null) {
                resolve(!candidates.length);
                return;
            }
            if (event.candidate.candidate.indexOf('.local') === -1)
                candidates.push(event.candidate.candidate);
        };
        pc.createOffer().then((offer) => {
            pc.setLocalDescription(offer);
        });
    });
}

async function doGetUserMedia() {
    var result = await navigator.mediaDevices.getUserMedia({video:true});
    return true;
}

window.onmessage = async (event) => {
    if (event.data === "checkFiltering") {
        event.source.postMessage(await isFilteringEnabled(), event.origin);
        return;
    }
    if (event.data === "capture") {
        event.source.postMessage(await doGetUserMedia(), event.origin);
        return;
    }
    event.source.postMessage("unknown message", event.origin);
}
    </script>
</body>
