Bug 219599 - clipboard (paste, copy, and cut) events don't fire on the focused element
Summary: clipboard (paste, copy, and cut) events don't fire on the focused element
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Safari 13
Hardware: Mac macOS 10.13
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-12-07 06:16 PST by Jimmy Thomsen
Modified: 2021-03-05 00:53 PST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jimmy Thomsen 2020-12-07 06:16:36 PST
Steps to reproduce the problem (copied from https://bugs.chromium.org/p/chromium/issues/detail?id=1156117):

1. Go to https://jsfiddle.net/62z9uwq1/
2. Follow the reproduction steps in the JSFiddle

AND..

This bug basically makes the combination of tabIndex + onPaste in popular frameworks such as ReactJS useless, as events are intercepted at the document level and dispatched to the appropriate element based on the event argument's target property.

A) Go to https://codesandbox.io/s/react-playground-forked-9juxn?file=/index.js
B) Click in "Table cell 1" and press CTRL + V: it works!
C) Press TAB to jump to "Table cell 2" and press CTRL + V: Nothing happens, because the global OnPaste event handler configured by ReactJS never receives an OnPaste event with "Table Cell 2" as event target - only <body> is received.

It's probably safe to assume that many other frameworks are affected too.

What is the expected behavior?
OnPaste must fire for elements that gain focus programmatically or via TAB navigation.

What went wrong?
OnPaste does not fire - only if user clicked on the element first.

OnPaste fires properly in Firefox v. 83 and IEEdge 18.

Chrome 87 and ChromiumEdge 87 are also affected by this bug.

Other browsers such as IE and Opera not tested.
Comment 1 Smoley 2020-12-07 14:22:15 PST
Thanks for filing, I can reproduce this on Safari 13.1.3 and STP 116.
Comment 2 Radar WebKit Bug Importer 2020-12-07 14:22:26 PST
<rdar://problem/72063887>
Comment 3 Jimmy Thomsen 2020-12-08 01:17:19 PST
Same bug applies to OnCopy and OnCut.
I have extended the JSFiddle to also register OnCopy and OnCut handlers:
https://jsfiddle.net/7puam9yr/1/

A fix should probably be tested against all relevant events.
Comment 4 Jimmy Thomsen 2020-12-08 04:28:22 PST
Programmatically invoking cut/copy/paste does not trigger the events either, nor does it modify the clipboard (unless clicking on the focusable element first).

document.execCommand("cut");
document.execCommand("copy");
document.execCommand("paste");
Comment 5 Ryosuke Niwa 2021-03-05 00:52:14 PST
This isn't really about whether an element is clicked but rather if the element has the selection or not. WebKit only fires the event on the selection's endpoints' common ancestor instead of the focused element.