Skip to content

Truly independent web browser

1.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script>internals.setAutoplayPolicy("allow-audio-and-video");</script>
<body>
<script>
promiseTest(async () => {
    const clock = new Audio("../../../Assets/test-webm-audio.ogg");
    clock.loop = true;
    clock.muted = true;
    await clock.play();
    async function wait(milliseconds) {
        const start = performance.now();
        while (performance.now() - start <= milliseconds)
            await new Promise(resolve => clock.addEventListener("timeupdate", resolve, { once: true }));
    }

    navigator.mediaSession.setPositionState({ duration: 100, position: 0 });
    await wait(300);
    const audio = new Audio(clock.src);
    const beforePlay = performance.now();
    await audio.play();
    audio.pause();
    const afterPause = performance.now();
    const position = internals.activeMediaSessionState().position.position;
    println(`time before playback doesn't count: ${position <= (afterPause - beforePlay) / 1000 + 0.05}`);
    clock.pause();
});
</script>