Skip to content

Fetch authenticated media through the session for "Save image as"#33997

Open
hayaksi1 wants to merge 1 commit into
element-hq:developfrom
hayaksi1:pr/desktop-save-image-authed
Open

Fetch authenticated media through the session for "Save image as"#33997
hayaksi1 wants to merge 1 commit into
element-hq:developfrom
hayaksi1:pr/desktop-save-image-authed

Conversation

@hayaksi1

Copy link
Copy Markdown

Problem

The desktop "Save image as" context-menu item fetched http(s) images with the main-process
global fetch(), which bypasses the session's webRequest interceptors — including the
authenticated-media handlers in media-auth.ts that rewrite the download URL and attach the
Authorization header. On modern Synapse (authenticated media, MSC3916) that request is rejected
with 401/404, so saving an image silently failed (#32362).

Fix

Extract the save logic into a dedicated save-image.ts and fetch network URLs through the image's
Electron session (webContents.session.fetch) instead of the global fetch, so the auth
interceptors apply. data: URLs are still decoded directly into a NativeImage. The module keeps
the extension-aware encoding (jpg/jpeg/bmp → PNG fallback) so its contract is unit-testable, and
webcontents-handler.ts now just delegates to it.

Tests

save-image.test.ts (Vitest, 7 passing) covers data:-URL decoding, the session-fetch path
(success, non-OK response, missing body), and the per-extension encoding.

Fixes #32362

Notes: Fixes "Save image as" failing on authenticated media (MSC3916) by fetching through the authenticated Electron session instead of the global fetch.

Checklist

The desktop "Save image as" context-menu item fetched http(s) images with the
main-process global fetch(), which bypasses the session's webRequest interceptors —
including the authenticated-media handlers in media-auth.ts that rewrite the download
URL and attach the Authorization header. On modern Synapse (authenticated media,
MSC3916) that fetch is rejected with 401/404, so saving an image failed (element-hq#32362).

Extract the save logic into a dedicated save-image.ts and fetch network URLs through
the image's Electron session (webContents.session.fetch) so the auth interceptors
apply; data: URLs are still decoded directly into a NativeImage. The module also keeps
the extension-aware encoding (jpg/jpeg/bmp/png) so its contract can be unit-tested.
@hayaksi1 hayaksi1 requested a review from a team as a code owner June 27, 2026 07:29
@hayaksi1 hayaksi1 requested review from dbkr and t3chguy June 27, 2026 07:29
@github-actions github-actions Bot added the Z-Community-PR Issue is solved by a community member's PR label Jun 27, 2026

@t3chguy t3chguy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane otherwise

@@ -0,0 +1,135 @@
/*
Copyright 2026 New Vector Ltd.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be your copyright, not that of the old name of our company

@@ -0,0 +1,52 @@
/*
Copyright 2026 New Vector Ltd.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Defect Z-Community-PR Issue is solved by a community member's PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"The image failed to save" when trying to "Save image as..." in Riot Desktop

2 participants