Repository navigation
Conversation
Download Image passed the focused Ferdium window to electron-dl, which takes the session from window.webContents. That is the default session, while each service lives in its own persist:service-<id> partition, so Google Chat attachment URLs redirected to accounts.google.com/ServiceLogin and the saved file was ServiceLogin.html. Download through the webContents that sent download-file instead. Copy Image re-requested srcURL through an <img> with crossOrigin set so it could draw it onto a canvas. That request carries an Origin header, and Google Chat's attachment endpoint answers it with an empty 204, so the image never loaded and the clipboard was never written. Copy the image the page already rendered with webContents.copyImageAt(x, y) instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-flight Checklist
Please ensure you've completed all of the following.
Description of Change
In a Google Chat service, open an image attachment or a screenshot and right-click it. Both image actions in Ferdium's context menu are broken:
ServiceLogin.html, and the file you get is Google's sign-in page rather than the image.They look related but have two separate causes.
Download Image downloads with the wrong session. The
download-filehandler passesBrowserWindow.getFocusedWindow()toelectron-dl, andelectron-dltakes the session fromwindow.webContents. For Ferdium's main window that is the default session. Each service runs in its ownpersist:service-<id>partition, and only that partition has the Google cookies. The attachment URL Chat puts insrcURL(chat.google.com/u/0/api/get_attachment_url?…) needs those cookies, so the download from the default session gets redirected to sign-in:ServiceLogin.html,text/html, redirectedget_attachment_url→accounts.google.com/ServiceLoginimage/png, redirectedget_attachment_url→lh3.googleusercontent.com/chat_attachment/…Copy Image re-requests the image in a way Google Chat refuses.
convertImageToBase64loadssrcURLagain throughnew Image()withcrossOrigin = 'Anonymous'so it can draw it onto a canvas. That turns it into a CORS request carrying anOriginheader, and Chat's attachment endpoint answers such requests with an empty204instead of redirecting to the image. The image fails to load.convertImageToBase64only listens forload, so the callback never runs and the clipboard is never written, but the notification is sent regardless. Captured with the network cache disabled, same attachment, same page:<img crossOrigin="anonymous">(current code, sendsOrigin)204 No Content,text/plain, no redirect<img>withoutcrossOrigin302→lh3.googleusercontent.com/chat_attachment/…→200 image/pngThis isn't a cookie problem — a same-origin anonymous request still sends cookies. It is the
Originheader.The fix
src/electron/ipc-api/download.ts: handelectron-dlthe webContents that sentdownload-file({ webContents: event.sender }) instead of the focused window, so the download goes through the requesting service's session. The save dialog, progress bar and badge behave as before. This also drops thewin!non-null assertion, whichgetFocusedWindow()does not guarantee.src/webview/contextMenuBuilder.ts: Copy Image now callswebContents.copyImageAt(x, y), the same pattern the builder already uses forinspectElement(x, y). It copies the image the page has already rendered, so nothing is fetched again and the result doesn't depend on how an endpoint treats CORS requests.Left untouched on purpose:
clipboard-write-image-data-urlIPC handler andwriteImageDataUrlToClipboardhelper from build: Update Electron to v43, Node.js to v24 and pnpm to v11 #2469 no longer have a caller in this path. I kept them out of this PR to keep it focused; happy to remove them here if you'd rather.blob:URLs still goes throughconvertImageToBase64. That path doesn't hit an authenticated endpoint, and I haven't changed its behaviour.Motivation and Context
Right-clicking an attachment or screenshot in Google Chat and copying or saving it is an everyday action, and today it silently does nothing (copy) or saves an HTML page (download). I couldn't find an existing issue for this.
Checklist
pnpm prepare-code)pnpm testpassesTests.
test/electron/ipc-api/download.test.tsis a regression test for the download half: ondevelopit fails becauseelectron-dlreceives the focused window's webContents (id: 1) instead of the requesting one (id: 42), and it passes with the fix. The full suite passes (18 suites, 141 passed, 2 skipped), andtsc --noEmit, ESLint, Biome and Prettier are clean.There is no automated test for Copy Image: that code runs in the webview preload through
@electron/remote, and the current test setup has no seam that exercises it realistically.Manual check, macOS (Apple Silicon), dev build of this branch (Electron 44.2.0), Google Chat signed in, an image attachment opened:
unnamed.webp,image/webp); the redirect chain wentget_attachment_url→lh3.googleusercontent.com/chat_attachment/…, started by the Chat webview rather than the default session.On the released 7.2.3 (Electron 43.3.0), the same steps produce
ServiceLogin.htmland an empty clipboard.Release Notes
Fixed "Copy Image" and "Download Image" for Google Chat attachments and screenshots.