From 59bf30f17fe61b1d15563b1022335f92dae9b913 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 23 Apr 2026 01:15:04 +0100 Subject: [PATCH] LibWeb: Add AVIF and WebP to the Accept header for images This matches the behavior of other engines. Some CDNs that do content negotiation will fall back to non alpha-preserving formats if these values are not present. --- Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 5 ++- .../expected/Fetch/image-accept-header.txt | 1 + .../Text/input/Fetch/image-accept-header.html | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/Fetch/image-accept-header.txt create mode 100644 Tests/LibWeb/Text/input/Fetch/image-accept-header.html diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index f25dc8fc567..213e5fbdb8e 100644 --- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -267,7 +267,10 @@ GC::Ref fetch(JS::Realm& realm, Infrastructure: // -> "image" case Infrastructure::Request::Destination::Image: // `image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5` - value = "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"sv; + // AD-HOC: The spec default omits AVIF and WebP, which causes CDNs that perform format negotiation to + // potentially fall back to non alpha-preserving formats. + // Spec issue: https://github.com/whatwg/fetch/issues/1740 + value = "image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"sv; break; // -> "json" case Infrastructure::Request::Destination::JSON: diff --git a/Tests/LibWeb/Text/expected/Fetch/image-accept-header.txt b/Tests/LibWeb/Text/expected/Fetch/image-accept-header.txt new file mode 100644 index 00000000000..df0f8f65332 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Fetch/image-accept-header.txt @@ -0,0 +1 @@ +image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5 diff --git a/Tests/LibWeb/Text/input/Fetch/image-accept-header.html b/Tests/LibWeb/Text/input/Fetch/image-accept-header.html new file mode 100644 index 00000000000..cc43eafd964 --- /dev/null +++ b/Tests/LibWeb/Text/input/Fetch/image-accept-header.html @@ -0,0 +1,32 @@ + + +