Skip to content

fix(browser): paste browser-copied images without rewriting the clipboard - #1041

Merged
rafatosta merged 2 commits into
rafatosta:mainfrom
zilch-gg:fix/browser-image-paste
Nov 16, 2026
Merged

rafatosta merged 2 commits into
rafatosta:mainfrom
zilch-gg:fix/browser-image-paste

Conversation

@zilch-gg

@zilch-gg zilch-gg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add features/browser/web/clipboard_image.py, which decides from mime.formats() whether the clipboard is image only (no real text, no copied local files) and reads the original image bytes
  • on Ctrl+V / Shift+Insert inside the page and on the context menu Paste, hand those bytes to WhatsApp Web as a File in a synthetic paste event, the same way paste_as_plain_text() already talks to the composer, with a drop on #main as fallback. Any other selection still gets QtWebEngine's native paste
  • remove the image normalization on window activation (changeEvent, _on_paste, _write_normalized_image), so ZapZap never writes to the global clipboard
  • replace test_clipboard_image_normalization.py with test_clipboard_image_paste.py, add image-paste to the probe vocabulary, update docs/testing.md, docs/maintenance.md, docs/reporting.md and the 7.5.2 changelog

Fixes #974. Refs #284, #498, #523, #969.

Cause

"Copy image" in Chromium, Brave and Vivaldi publishes something like this (Brave 157 on Plasma Wayland):

text/x-moz-url
text/html
image/png
chromium/x-internal-source-rfh-token
chromium/x-source-url

There is no text/plain, but on the Qt side the URL shows up as text/uri-list and QMimeData.hasText() returns true for that. _on_paste() bails out on hasText() to protect spreadsheet clipboards (#498), so the normalization never ran for the case it was added for. That matches what the reporter of #974 saw.

Without the normalization, QtWebEngine doesn't give the page the image either. I offered the same set of formats from a separate Qt process and pasted into a plain contenteditable in a QWebEnginePage: the paste event only had text/uri-list, no file, and clipboard.image() was null even though image/png was on offer. ClipboardQt::ReadPng builds the PNG from mimeData->imageData() instead of using the raw image/png bytes, so when that conversion fails the page gets nothing. I only got one clean run of that before Klipper started re-offering my test selections, so I haven't pinned down why imageData() comes back empty.

Following your comment in #974, this doesn't touch the global clipboard at all. ZapZap reads the bytes it needs and passes them to the page itself, so the LibreOffice breakage from #498 and the stale-image overwrites from #523 and #969 can't come back through this path.

Behaviour change

Ctrl+V used to be left entirely to QtWebEngine, and docs/reporting.md said so. Now it is intercepted only when the selection is image only. Text, HTML with a text/plain part (LibreOffice cells, rich text) and files copied from a file manager still take the native path. Images over 64 MiB also fall back to the native paste, so a huge clipboard can't stall the UI while it is base64 encoded for runJavaScript.

Verification

On KDE Plasma 6.8.2 (Wayland), Brave "Copy image" followed by Ctrl+V in a chat opened WhatsApp's attachment preview with the image, once, on each of four tries. WhatsApp cancelled the synthetic paste every time, so the drop fallback never ran against the real site. It is only covered by the WebEngine test.

I didn't re-check LibreOffice cells by hand on this build. The selection rules for that case are covered by the unit tests.

Tests

  • python tests/test_clipboard_image_paste.py -v (12 passed)
  • python -m unittest discover -s tests -q (796 run, 4 failures and 4 errors). The same 8 fail on upstream/main without this change: the four dictionary UI tests ('types.SimpleNamespace' object has no attribute 'pdf_click_behavior'), test_account_context_menu_waits_for_keyboard_before_focusing_action, the macOS PyInstaller check and the two zh_CN catalog tests
  • python tests/check_unused_code.py --packages-only
  • python tests/test_documentation_structure.py -v (8 passed)
  • python -m compileall -q zapzap tests tools run.py
  • git diff --check
  • each unittest discover -p pattern from .github/workflows, run on its own

These ran on the host's PyQt6, not inside the Flatpak, because I don't have the Flatpak installed.

Notes

The ReadPng behaviour above is probably worth a Qt bug report, since it affects any QtWebEngine app pasting browser images. I can file it if I manage to get a clean reproduction.

Environment: CachyOS, KDE Plasma 6.8.2, Wayland, x86_64, Python 3.14, Qt 6.12.0, QtWebEngine 6.11.3, PyQt6 6.12.0, PyQt6-WebEngine 6.11.0, Brave 157.

…oard

Images copied with "Copy image" in Chromium-based browsers did nothing on
Ctrl+V (rafatosta#284, rafatosta#974). Those selections carry a URL, HTML and image/png but
no text/plain. QtWebEngine handed the page no file for them, and the
normalization on window focus skipped them because QMimeData.hasText() is
true for a selection that only has URLs.

When the clipboard has an image and no real text or copied local files,
read the image bytes directly and hand them to WhatsApp Web as a File in a
synthetic paste event, with a drop on #main as a fallback. Ctrl+V,
Shift+Insert and the context menu Paste go through this. Anything else
keeps the native paste. Remove the normalization on focus, so ZapZap no
longer writes to the clipboard when it gains focus (rafatosta#498, rafatosta#523, rafatosta#969).

Tests:
- python tests/test_clipboard_image_paste.py -v (10 passed)
- python -m unittest discover -s tests -q (794 run, 4 failures and
  4 errors, the same 8 as on upstream/main without this change)
- python tests/check_unused_code.py --packages-only
- python tests/test_documentation_structure.py -v (8 passed)
- python -m compileall -q zapzap tests tools run.py
- git diff --check
- Manual: Brave "Copy image" then Ctrl+V on KDE Plasma (Wayland) opens
  WhatsApp's attachment preview with the image once.
The event filter called QKeyEvent.matches(StandardKey.Paste) on every key
press. matches() looks up the platform key bindings, and with no
QGuiApplication it segfaults, which crashed
test_escape_and_close_conversation_discard_suggestion when CI runs
test_download_settings.py on its own. Check the key code first, so only
V, Insert, F18 and Paste reach matches(). It also keeps the lookup off
ordinary typing.

Add filter tests for Ctrl+V and for keys that must not reach the image
path.

Tests:
- python -m unittest tests.test_download_settings.SaveAsDirectoryTests.test_escape_and_close_conversation_discard_suggestion
  (crashed before, passes now)
- each unittest discover -p pattern from .github/workflows, run on its own
- python tests/test_clipboard_image_paste.py -v (12 passed)
- python -m unittest discover -s tests -q (796 run, same 8 failures as
  upstream/main)
@rafatosta
rafatosta merged commit 67073c2 into rafatosta:main Nov 16, 2026
4 checks passed
@zilch-gg
zilch-gg deleted the fix/browser-image-paste branch November 16, 2026 20:48
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.

Image copied from Vivaldi does not paste in ZapZap 7.5 Flatpak on KDE Wayland; plain text works

2 participants