LibWeb/PermissionsPolicy: Allow autoplay of file:// media from file://

As file:// URLs are considered opaque origins by default, we need
to special case them in the allowlist as any opaque origin will
not be matched in the allow list.
This commit is contained in:
Shannon Booth 2026-02-28 20:45:34 +01:00 committed by Shannon Booth
parent 336d95ebdc
commit e188de89f9
3 changed files with 25 additions and 0 deletions

View file

@ -44,6 +44,10 @@ Decision AutoplayAllowlist::is_allowed_for_origin(DOM::Document const& document,
for (auto const& pattern : patterns) {
if (pattern.is_same_origin_domain(origin))
return Decision::Enabled;
// AD-HOC: Allow autoplay for file:// URLs if the document is also from a file:// URL.
if (origin.is_opaque_file_origin() && document.origin().is_opaque_file_origin())
return Decision::Enabled;
}
return Decision::Disabled;
@ -57,6 +61,10 @@ Decision AutoplayAllowlist::is_allowed_for_origin(DOM::Document const& document,
if (origin.is_same_origin(document.origin()))
return Decision::Enabled;
// AD-HOC: Allow autoplay for file:// URLs if the document is also from a file:// URL.
if (origin.is_opaque_file_origin() && document.origin().is_opaque_file_origin())
return Decision::Enabled;
// 6. Return "Disabled".
return Decision::Disabled;
}

View file

@ -0,0 +1 @@
PASS: autoplay working

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<video autoplay id="video" src="../../../Assets/test-webm.webm" muted></video>
<script src="../include.js"></script>
<script>
asyncTest(done => {
setTimeout(() => {
println("FAIL: timeout waiting for autoplay");
done();
}, 10_000);
video.onplaying = () => {
println("PASS: autoplay working");
done();
};
});
</script>