Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should reading the clipboard throw DataError or empty clipboard items? #179

Closed
snianu opened this issue Jun 10, 2022 · 6 comments
Closed
Labels

Comments

@snianu
Copy link
Contributor

snianu commented Jun 10, 2022

https://w3c.github.io/clipboard-apis/#dom-clipboard-read suggests that reading the clipboard and not returning any items (such as when only unsupported types are on the clipboard) should return an empty list. In Chrome, we throw a DataError. Should we return an empty clipboardItem (to match the spec) or change the spec to throw DataError?
@annevk @mbrodesser @BoCupp-Microsoft @whsieh

@snianu snianu added the Agenda+ label Jun 10, 2022
@css-meeting-bot
Copy link
Member

The Web Editing Working Group just discussed should reading the clipboard throw DataError or empty clipboard items?.

The full IRC log of that discussion <Travis> topic: should reading the clipboard throw DataError or empty clipboard items?
<Travis> github: https://github.com//issues/179
<Travis> (reads the issue)
<Travis> whsieh_: this is the situation where there IS data on the clipboard, but none of it can be consumed by the webpage...?
<Travis> .. seems weird to throw a DataError in the case where there is nothing in the clipboard/pasteboard...
<Travis> .. in that case, returning an empty list.
<Travis> travis: I like just returning an empty list too--easy for web authors to handle with erroring out...
<Travis> whsieh_: In the specific example that snianu (Anupam) gave, I'm not sure if the error is OK.
<Travis> .. probably can't resolve on this at this time without further discussion with snianu?
<Travis> s/snianu?/snianu.
<Travis> johanneswilm: can the JS Editors differentiate between the different error conditions?
<Travis> .. could the user re-request? E.g., if the user didn't grant permission?
<Travis> whsieh_: recap; there are cases where a website might want to know whether they can try again, or whether they shouldn't try again.
<Travis> .. empty list vs throw error could be a way to differentiate.
<Travis> johanneswilm: there are two other cases...
<Travis> .. one where the user didn't give access, and one where the clipboard is changed after access is granted.
<Travis> whsieh_: in the first case, Safari throws "NotAllowed" (from the user denying paste).
<Travis> .. in the case where it changed, we also throw an error; but the type of error may not make sense...
<Travis> .. could look at changing it?
<Travis> (no resolution yet)

@EdgarChen
Copy link

In Gecko, we don't throw error, either, though we have a bug where we return a clipboard item with empty types currently, https://bugzilla.mozilla.org/show_bug.cgi?id=1756955.

@css-meeting-bot
Copy link
Member

The Web Editing Working Group just discussed Should reading clipboard throw or return empty?.

The full IRC log of that discussion <Travis> Topic: Should reading clipboard throw or return empty?
<Travis> github: https://github.com//issues/179
<Travis> snianu: Seems like a similar issue to 180.
<Travis> .. if there's no HTML format in the clipboard, and the author tries to read HTML format, then what?
<Travis> .. makes sense to throw a DataError.
<Travis> .. even though the clipboard has some data, just not what is desired.
<Travis> snianu: If authors are trying to read HTML, but the clipboard has something that's not in the supported types.
<Travis> .. the clipboard item won't have any data.
<Travis> whsieh: interesting to note: clipboard being empty is a valid system state.
<Travis> .. ex: calling clear contents from the OS. The technical truth is that there are no items in the clipboard.
<Travis> .. how would authors use this knowledge?
<Travis> .. (trying to come up with a scenario)
<Travis> .. I guess it makes sense (either way we go) to have some consistency.
<Travis> snianu: Currently we throw DataError in Chromium. So does Firefox.
<Travis> whsieh: Pretty sure Webkit will return an empty array of items.
<Travis> .. I think we can adjust our behavior to match; a DataError seems pretty sensible.

@annevk
Copy link
Member

annevk commented Oct 1, 2022

Throwing seems a little weird to me when there is no data to return. If there truly is no data an empty sequence seems good. And if there is an item but its types cannot be read I could somewhat see wanting to filter such items out, but that might also make it harder to provide decent UI indicating to the user what might have gone wrong. So I'd prolly return the item with no exposed types for that case.

@snianu
Copy link
Contributor Author

snianu commented Nov 7, 2023

@evanstade FYI..

@snianu snianu mentioned this issue Nov 7, 2023
4 tasks
@snianu
Copy link
Contributor Author

snianu commented Nov 9, 2023

RESOLUTION: Keep the exception during write(), but return empty ClipboardItem during read() if system clipboard is empty.
Full discussion:
[17:25] next up: #198
[17:26] trying to speak
[17:26] can you hear me?
[17:26] snianu: audio issues, let's move on for now
[17:26] snianu: nvm audio issues fixed!
[17:27] snianu: if clipboard item is empty and developer writes to clipboard, the write will throw an exception in Chrome but FF/WebKit allows that
[17:28] s/clipboard item is empty/clipboard item list is empty/
[17:28] snianu: creates confusion for web dev since it's unclear if they need to retry, or…
[17:28] q+
[17:29] q+
[17:29] s/developer writes to clipboard/developer reads from clipboard/
[17:29] q-
[17:29] snianu: read should not throw exception, write should throw exception
[17:30] snianu: with current DT APIs dev cannot clear clipboard by writing
[17:30] snianu: with async clipboard API you can write empty item (?)
[17:30] snianu: maybe flag to indicate that clipboard item is intentionally "empty"
[17:30] q+
[17:32] whsieh: if we want to expose a "clear clipboard" API, it should probably be navigator.clipboard.clear() or something
[17:33] johanneswilm: seems we're all in agreement
[17:33] sanketj_: to summarize, allow read empty items

@snianu snianu closed this as completed Nov 9, 2023
@snianu snianu added the RESOLVED label Nov 9, 2023
aarongable pushed a commit to chromium/chromium that referenced this issue Nov 17, 2023
Record when an empty clipboard is encountered during `read()`.

Gathering data for w3c/clipboard-apis#179.

Bug: 1500440

Change-Id: I7c9c162ec7e17ea18a42683c9720330cbac57b3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029806
Reviewed-by: Evan Stade <[email protected]>
Commit-Queue: Anupam Snigdha <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1225837}
aarongable pushed a commit to chromium/chromium that referenced this issue Dec 7, 2023
Empty clipboard is a valid system state.
Allow `read()` to return an empty ClipboardItem without rejecting
the promise if
(a) there are no formats on the clipboard.
(b) there are unsupported formats on the clipboard.

Prevent `write()` from writing empty ClipboardItem by keeping
the `TypeError` exception in the ClipboardItem when it's called
from JS. It's not clear whether writing empty ClipboardItem should
clear the clipboard or write empty data for all supported formats
or do nothing.

Github issue: w3c/clipboard-apis#179

I2S: https://groups.google.com/a/chromium.org/g/blink-dev/c/FAchVmgepKM/m/-V91uCcCAAAJ?utm_medium=email&utm_source=footer

Bug: 1500440

Change-Id: I654cb3e92e30f034cad5812e65776ec173b7dccc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5010104
Reviewed-by: Kent Tamura <[email protected]>
Reviewed-by: Sanket Joshi <[email protected]>
Commit-Queue: Anupam Snigdha <[email protected]>
Reviewed-by: Evan Stade <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1234340}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Mar 28, 2024
…e is only unsupported items in system clipboard; r=nika

This aligns with the current spec. There are some discussion in
w3c/clipboard-apis#179.

Differential Revision: https://phabricator.services.mozilla.com/D205502
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this issue Apr 1, 2024
…e is only unsupported items in system clipboard; r=nika

This aligns with the current spec. There are some discussion in
w3c/clipboard-apis#179.

Differential Revision: https://phabricator.services.mozilla.com/D205502
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants