postprocess: Fix animated images automatically playing on Firefox.

This commit fixes a bug where animated images automatically play on
Firefox because the image source didn't output the same URL across
different browsers. Currently, the image source is normalized to
ensure consistent URLs across different browsers.

Fixes #33248

Co-authored-by: Alex Vandiver <alexmv@zulip.com>
This commit is contained in:
Abel Abate
2025-02-17 21:16:05 +03:00
committed by Tim Abbott
parent df7ad517c5
commit 2e95012c90

View File

@@ -108,7 +108,15 @@ export function postprocess_content(html: string): string {
"div.message_inline_image > a > img",
)) {
inline_img.setAttribute("loading", "lazy");
if (inline_img.src.startsWith("/user_uploads/thumbnail/")) {
// We can't just check whether `inline_image.src` starts with
// `/user_uploads/thumbnail`, even though that's what the
// server writes in the markup, because Firefox will have
// already prepended the origin to the source of an image.
const image_url = new URL(inline_img.src, window.location.origin);
if (
image_url.origin === window.location.origin &&
image_url.pathname.startsWith("/user_uploads/thumbnail/")
) {
let thumbnail_name = thumbnail.preferred_format.name;
if (inline_img.dataset.animated === "true") {
if (