Skip to content

Insert: paste into a WKWebView page field, confirmed by its value (#5) - #251

Merged
iamnbutler merged 3 commits into
mainfrom
web-input-paste
Nov 12, 2026
Merged

iamnbutler merged 3 commits into
mainfrom
web-input-paste

Conversation

@iamnbutler

Copy link
Copy Markdown
Contributor

Closes the remaining item of #5: desktop_insert with route: "paste" (or the default route when a field is focused) into a web <input> was refused before anything was sent.

Cause

Two problems, both in Mac.pasteText:

  1. It checked keyboard focus before making an inactive app's window key. A background WKWebView window that isn't key reports no focused window, so the check refused: "Exact-window keyboard focus is not on the target window". The window was made key only later, inside paste. Typing already prepares the window first (prepareKeys, Keys to a list in a non-key window return completed but never reach it #226/Keys reach a SwiftUI List and a WebKit page in the background; web terminals are typed into, never pasted #240).
  2. The baseline and read-back (ReceiverState.read) required the app's AXFocusedUIElement to be the field. A WKWebView app names none. The page field reports AXFocused itself, which requireKeyboardFocus already handles through focusedWebElement (Keys reach a SwiftUI List and a WebKit page in the background; web terminals are typed into, never pasted #240).

Change

pasteText now calls prepareKeys before checking focus. prepareKeys makes the window key without moving focus between windows. The receiver read accepts the app's focused element, or else the focused page field in its focused window. The paste is then confirmed by the field's value and selection, as for native fields, and the clipboard is restored after it shows.

Checked

On the WKWebView fixture (native2/fixture/webfix.swift), through the standalone host built from this branch, relaunching the fixture each time so its window starts out not key:

  • 3 cold runs × <input>, <textarea> and contenteditable composer: 9/9 completed, consumption: observed, clipboard_cleanup: restored. The page logged exactly one paste and one input per field.
  • The default route (no route) into the <input>: completed, and the page logged the paste.
  • Before the change: refused with "Exact-window keyboard focus is not on the target window at dispatch".
  • swift test --package-path native2 passes.

One attempt right after my first edit was still refused with the focus message. I couldn't reproduce it in the cold runs above. If it recurs, the likely cause is prepareKeys' 0.5 s wait for the page to give focus back to the field after the window becomes key. Safari wasn't touched.

🤖 Generated with Claude Code

iamnbutler and others added 3 commits November 12, 2026 14:54
desktop_insert's paste route into a web <input>, <textarea> or contenteditable in a
background WKWebView app was refused before sending: the window wasn't key, so the
app reported no focused window, and a WKWebView app names no AXFocusedUIElement, so
the field's text couldn't be read back. pasteText now makes an inactive app's window
key first (prepareKeys, as typing does), and the receiver read accepts the page
field that reports AXFocused itself.

Why: native2/Sources/DesktopMac/Paste.swift | a WKWebView app names no AXFocusedUIElement and its window must be key before the page field reports focus; prepare the window, then find the field through focusedWebElement, before reading the baseline

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamnbutler
iamnbutler merged commit 7885888 into main Nov 12, 2026
2 checks passed
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