Bug 263724 - document.execCommand("paste") has a different behavior in browsers
Summary: document.execCommand("paste") has a different behavior in browsers
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Safari 17
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks: 263725
  Show dependency treegraph
 
Reported: 2023-10-26 08:38 PDT by Karl Dubost
Modified: 2023-10-26 09:18 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Karl Dubost 2023-10-26 08:38:04 PDT
In Bug 263590, a Quirk has been created to handle a double paste issue with the Tableau application.

Some background for document.queryCommandSupported("paste")
https://www.w3.org/2017/09/05-editing-minutes.html#item02
https://bugs.chromium.org/p/chromium/issues/detail?id=757140
https://bugzilla.mozilla.org/show_bug.cgi?id=1161721

The specification is not in a good place.
https://w3c.github.io/editing/docs/execCommand/

Kind of related specs too.
https://w3c.github.io/clipboard-apis/#clipboard-event-paste
and https://w3c.github.io/input-events/#event-order-when-using-insertfrompaste

According to this test, paste is supported in privileged context in Firefox.
https://github.com/mozilla/gecko-dev/blob/df57c7356a3a2465412b76a403a7b24a46c369a4/dom/tests/mochitest/general/test_bug1161721.html#L22

And probably in Chromium (to find out)
Comment 1 Radar WebKit Bug Importer 2023-10-26 08:38:16 PDT
<rdar://problem/117535610>
Comment 2 Karl Dubost 2023-10-26 09:18:09 PDT
In Bug 263590 where the Quirk was created for Tableau app, see the commit message from Wenson:

==========
In Tableau's analytics tool, pressing ⌘V to paste in any focused editable areas pastes content twice after showing a Paste menu item, if the user clicks "Paste" on this item. This is because Tableau's script does something akin to the following:

```
textField.addEventListener("keydown", event => {
    if (event.key === "v" && event.metaKey)
        document.execCommand("Paste");
});
```

... which triggers a programmatic paste upon `keydown`, without preventing default. This means that if the programmatic DOM paste is accepted, we'll end up triggering two paste commands: 

  (1) due to the `execCommand`, and 
  (2) due to the default behavior of ⌘V.

While this is ostensibly a website bug, it works fine in other browsers (Firefox, Chrome) because they don't support DOM paste at all, so we just end up silently failing the programmatic paste before performing the real paste.
==========

Firefox, and Chrome seems to support paste but they do not expose it to the Web or only under certain circumstances.

Firefox
https://searchfox.org/mozilla-central/source/dom/base/Document.cpp#5404-5409