Skip to content

fix: make Copy Image and Download Image work for Google Chat attachments - #2559

Open
anhvu-sg wants to merge 1 commit into
ferdium:developfrom
anhvu-sg:fix/google-chat-image-copy-download
Open

anhvu-sg wants to merge 1 commit into
ferdium:developfrom
anhvu-sg:fix/google-chat-image-copy-download

Conversation

@anhvu-sg

@anhvu-sg anhvu-sg commented Sep 14, 2026 •

Copy link
Copy Markdown

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:

  • Copy Image shows the "Image copied" notification, but nothing lands on the clipboard, so there is nothing to paste.
  • Download Image (macOS) opens a save dialog proposing 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-file handler passes BrowserWindow.getFocusedWindow() to electron-dl, and electron-dl takes the session from window.webContents. For Ferdium's main window that is the default session. Each service runs in its own persist:service-<id> partition, and only that partition has the Google cookies. The attachment URL Chat puts in srcURL (chat.google.com/u/0/api/get_attachment_url?…) needs those cookies, so the download from the default session gets redirected to sign-in:

downloaded through result
Ferdium window (current code) ServiceLogin.html, text/html, redirected get_attachment_url → accounts.google.com/ServiceLogin
the Chat webview's own session image/png, redirected get_attachment_url → lh3.googleusercontent.com/chat_attachment/…

Copy Image re-requests the image in a way Google Chat refuses. convertImageToBase64 loads srcURL again through new Image() with crossOrigin = 'Anonymous' so it can draw it onto a canvas. That turns it into a CORS request carrying an Origin header, and Chat's attachment endpoint answers such requests with an empty 204 instead of redirecting to the image. The image fails to load. convertImageToBase64 only listens for load, 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:

request response
<img crossOrigin="anonymous"> (current code, sends Origin) 204 No Content, text/plain, no redirect
<img> without crossOrigin 302 → lh3.googleusercontent.com/chat_attachment/… → 200 image/png

This isn't a cookie problem — a same-origin anonymous request still sends cookies. It is the Origin header.

The fix

  • src/electron/ipc-api/download.ts: hand electron-dl the webContents that sent download-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 the win! non-null assertion, which getFocusedWindow() does not guarantee.
  • src/webview/contextMenuBuilder.ts: Copy Image now calls webContents.copyImageAt(x, y), the same pattern the builder already uses for inspectElement(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:

  • The clipboard-write-image-data-url IPC handler and writeImageDataUrlToClipboard helper 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.
  • Download Image for blob: URLs still goes through convertImageToBase64. 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

  • My pull request is properly named
  • The changes respect the code style of the project (pnpm prepare-code)
  • pnpm test passes
  • I tested/previewed my changes locally

Tests. test/electron/ipc-api/download.test.ts is a regression test for the download half: on develop it fails because electron-dl receives 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), and tsc --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:

  • Download Image saved the actual image (unnamed.webp, image/webp); the redirect chain went get_attachment_url → lh3.googleusercontent.com/chat_attachment/…, started by the Chat webview rather than the default session.
  • Copy Image put the image on the clipboard and it pasted correctly.

On the released 7.2.3 (Electron 43.3.0), the same steps produce ServiceLogin.html and an empty clipboard.

Release Notes

Fixed "Copy Image" and "Download Image" for Google Chat attachments and screenshots.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant