fix: make drag-and-drop work on Linux (capture-and-inject) — v0.4.1#7
Merged
Conversation
…nject
v0.4.0 disabled Tauri's drag-drop handler and relied on the webview
delivering the OS file drop to the page as an HTML5 drop. On Linux
webkit2gtk that never happens — broken on Wayland, and on X11 the GTK
drop is accepted (the '+' cursor shows) but it still never reaches
web.whatsapp.com's DOM. So dropping a file did nothing.
Instead, keep Tauri's drag-drop handler enabled, capture the drop in
Rust (WindowEvent::DragDrop, which works at the GTK level on both
Wayland and X11), read the file off the UI thread, base64 it, and eval
an injection into the page. bridge.js __whatrustHandleDrop rebuilds the
File and feeds it to WhatsApp's own attach flow: primary path sets a
hidden <input type=file>'s .files and fires change (React fires onChange
for synthetic events; isTrusted is not checked); fallback dispatches a
synthetic drop using a plain Event with dataTransfer defined via
Object.defineProperty (new DragEvent('drop',{dataTransfer}) silently
nulls dataTransfer in WebKit). WhatsApp opens a preview/Send composer
(never auto-sends), so attempting both paths is safe.
Verified end-to-end on real WhatsApp Web (Wayland + X11, image + doc).
Injection mechanics confirmed against webkit2gtk 2.52. Boundary
diagnostics go to the existing file log (new js-callable dlog command).
Release v0.4.1.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
v0.4.0 added drag-and-drop by disabling Tauri's drag-drop handler and relying on the webview delivering the OS file drop to the page as an HTML5 drop. On Linux/webkit2gtk that never happens — broken on Wayland, and on X11 the GTK drop is accepted (the
+cursor shows) but it still never reachesweb.whatsapp.com's DOM. Result: dropping a file did nothing.Fix — capture-and-inject
Keep Tauri's drag-drop handler enabled and:
WindowEvent::DragDrop) — this works at the GTK level on both Wayland and X11 (the part that was working all along).evalan injection into the page.bridge.js __whatrustHandleDroprebuilds theFileand feeds it to WhatsApp's own attach flow:<input type=file>'s.files+ firechange(React firesonChangefor synthetic events;isTrustedis not checked).EventwithdataTransferdefined throughObject.defineProperty— becausenew DragEvent('drop',{dataTransfer})silently nullsdataTransferin WebKit.No
GDK_BACKEND=x11forcing needed — works Wayland-native.Verification
.sh); the media composer opened both times.input.files+change, and thedefinePropertydrop all deliver the file).cargo build --locked+cargo test --locked→ 51/51 (incl. RFC 4648 base64 vectors). CI covers Windows + macOS.dlogcommand) so future DnD issues can be traced without a console.Releases as v0.4.1.
🤖 Generated with Claude Code