Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<link rel="author" title="Squarespace" href="https://www.squarespace.com/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.below-viewport {
margin-top: 1000vh;
}
</style>
<body>
<script>
const t = async_test(
"Audio with loading=lazy and autoplay that is not visible in viewport does not load audio data or autoplay"
);
const audio = document.createElement("audio");
audio.loading = "lazy";
audio.src = "/media/sine440.mp3";
audio.className = "below-viewport";
audio.autoplay = true;
audio.controls = true;
audio.addEventListener("loadstart", () => {
assert_unreached("Audio should not fire loadstart event when not visible in viewport");
});
document.body.appendChild(audio);
t.step_timeout(() => {
assert_equals(audio.readyState, HTMLMediaElement.HAVE_NOTHING);
assert_true(audio.paused, "Audio should not autoplay when not visible in viewport");
t.done();
}, 2000);
</script>
</body>