Repository navigation
fix(browser): paste browser-copied images without rewriting the clipboard - #1041
Merged
Merged
Conversation
…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
approved these changes
Nov 16, 2026
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.
Summary
features/browser/web/clipboard_image.py, which decides frommime.formats()whether the clipboard is image only (no real text, no copied local files) and reads the original image bytesFilein a syntheticpasteevent, the same waypaste_as_plain_text()already talks to the composer, with adropon#mainas fallback. Any other selection still gets QtWebEngine's native pastechangeEvent,_on_paste,_write_normalized_image), so ZapZap never writes to the global clipboardtest_clipboard_image_normalization.pywithtest_clipboard_image_paste.py, addimage-pasteto the probe vocabulary, updatedocs/testing.md,docs/maintenance.md,docs/reporting.mdand the 7.5.2 changelogFixes #974. Refs #284, #498, #523, #969.
Cause
"Copy image" in Chromium, Brave and Vivaldi publishes something like this (Brave 157 on Plasma Wayland):
There is no
text/plain, but on the Qt side the URL shows up astext/uri-listandQMimeData.hasText()returns true for that._on_paste()bails out onhasText()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
contenteditablein aQWebEnginePage: thepasteevent only hadtext/uri-list, no file, andclipboard.image()was null even thoughimage/pngwas on offer.ClipboardQt::ReadPngbuilds the PNG frommimeData->imageData()instead of using the rawimage/pngbytes, 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 whyimageData()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.mdsaid so. Now it is intercepted only when the selection is image only. Text, HTML with atext/plainpart (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 forrunJavaScript.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 testspython tests/check_unused_code.py --packages-onlypython tests/test_documentation_structure.py -v(8 passed)python -m compileall -q zapzap tests tools run.pygit diff --checkunittest discover -ppattern from.github/workflows, run on its ownThese ran on the host's PyQt6, not inside the Flatpak, because I don't have the Flatpak installed.
Notes
The
ReadPngbehaviour 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.