Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
id: 01M78N6R3R77484F4KP21TYPXX
anchor: '@file'
created: 2026-11-12T19:54:24Z
norm: '1'
sig: 27abcba5e975f16e
body_hash: d23058b9832794d1
raw_hash: cf982114ea9b7925
lines: 1-595
supersedes: 01M5D5AB34JDWZ565DVTAB86HD
---

pasteAttachment: the receiver check comes before requireKeyboardFocus so a background web field gets PASTE_UNVERIFIABLE_RECEIVER, as on Node, not a focus refusal. pasteText instead prepares the window first, since a web field's text paste can be read back (#5)
8 changes: 7 additions & 1 deletion native2/Sources/DesktopMac/Paste.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ private struct ReceiverState {
func focusedValue() -> String? {
let app = AXUIElementCreateApplication(window.pid)
AXUIElementSetMessagingTimeout(app, 0.2)
// A WKWebView app names no focused element; its page field reports AXFocused itself (#5).
guard Mac.generation(window.pid) == window.generation,
let focused = AX.element(AX.value(app, kAXFocusedUIElementAttribute)), CFEqual(focused, element),
let focused = AX.element(AX.value(app, kAXFocusedUIElementAttribute))
?? AX.element(AX.value(app, kAXFocusedWindowAttribute)).flatMap(Mac.focusedWebElement),
CFEqual(focused, element),
let frame = AX.frame(element), window.bounds.contains(CGPoint(x: frame.midX, y: frame.midY))
else { return nil }
return AX.string(element, kAXValueAttribute)
Expand Down Expand Up @@ -307,6 +310,9 @@ extension Mac {
throw pasteRefusal("Literal insertion requires 1–8192 UTF-16 units and an exact focused receiver.")
}
return try ClipboardGate.exclusive { transaction in
// An inactive app's window must be key before its focus can be checked and the paste read back, as typing
// does (#226): a WKWebView window that isn't key reports no focused field (#5).
_ = try prepareKeys(target)
let focused = try requireKeyboardFocus(target)
if secureFocus(focused) { throw secureFocusRefusal }
guard let baseline = ReceiverState.read(focused, target: target),
Expand Down
Loading