Answer paste keystrokes from the paste event on wasm - #25396
Open
Cyannide wants to merge 2 commits into
Open
Conversation
navigator.clipboard.readText() sits behind Chrome's clipboard-read permission (a prompt on first paste, per origin) and does not exist for page JS on Firefox. The text a paste KEYSTROKE carries is readable without any permission from the `paste` ClipboardEvent -- the gesture is the grant; this is how web editors avoid the prompt. A window-level `paste` listener (installed at plugin build, leaked on purpose) stashes the event's text with its arrival time; fetch_text() consumes a fresh stash entry before touching readText(), which remains the fallback for reads no paste event drove. Degrades gracefully: winit currently preventDefault()s every keydown when prevent_default is on (bevy's default), which suppresses the browser's paste event -- there the stash stays empty and behavior is exactly today's readText() path. Fully effective once the app disables prevent_default_event_handling or winit spares clipboard combos (rust-windowing/winit#2831; a 6-line exemption is field-tested). Part of bevyengine#25340.
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.
Objective
navigator.clipboard.readText()sits behind Chrome's clipboard-read permission (a prompt on first paste, per origin) and does not exist for page JS on Firefox. The text a paste KEYSTROKE carries is readable without any permission from thepasteClipboardEvent-- the gesture is the grant; this is how web editors avoid the prompt.Solution
A window-level
pastelistener (installed at plugin build, leaked on purpose; the closure is forget()-ed; it must outlive the app) stashes the event's text with its arrival time;fetch_text()consumes a fresh stash entry before touchingreadText(), which remains the fallback for reads no paste event drove.Degrades gracefully:
winitcurrentlypreventDefault()s every keydown whenprevent_defaultis on (Bevy's default), which suppresses the browser's paste event -- there the stash stays empty and behavior is exactly today'sreadText()path. Fully effective once the app disablesprevent_default_event_handlingorwinitspares clipboard combos (rust-windowing/winit#2831; a 6-line exemption is field-tested).Part of #25340.
Testing
exemption above): Chrome pastes with no permission prompt where it
prompted before, Firefox pastes at all (readText() does not exist there),
Safari stops showing its paste confirmation. About a month of daily
tester use on the rest of the patch set; this piece landed this week.
readText() fallback is the untouched existing code path -- behavior is
identical to main by construction. Reproducible without a patched winit
by setting
Window::prevent_default_event_handling = false.cargo checkand clippy, x86_64 and wasm32-unknown-unknown,with and without
system_clipboard.