Skip to content

Commit 70a1845

Browse files
authored
update explainer for empty types (#1133)
Update the explainer to not fallback to default behavior of no filtering when `types` is empty array. See #1129 for more details.
1 parent ce3d4d8 commit 70a1845

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

ClipboardAPI/SelectiveClipboardFormatRead/explainer.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ We propose API signature changes to the [clipboard.read()](https://www.w3.org/TR
7272

7373
We propose to rename the optional argument [`ClipboardUnsanitizedFormats`](https://www.w3.org/TR/clipboard-apis/#dictdef-clipboardunsanitizedformats) of [read()](https://www.w3.org/TR/clipboard-apis/#dom-clipboard-read) API to [`ClipboardReadOptions`](#appendix-1-proposed-idl) and extend this object to include a new `types` property which is a list of mime types to be retrieved.
7474

75-
Existing implementations and web applications that use [navigator.clipboard.read()](https://www.w3.org/TR/clipboard-apis/#dom-clipboard-read) without specifying types or with empty MIME types will continue to behave as before, receiving all available clipboard formats.
75+
Existing implementations and web applications that use [navigator.clipboard.read()](https://www.w3.org/TR/clipboard-apis/#dom-clipboard-read) will continue to behave as before when `types` is `undefined`, receiving all available clipboard formats.
7676

7777
If a MIME type is provided in [`unsanitized`](https://www.w3.org/TR/clipboard-apis/#dom-clipboardunsanitizedformats-unsanitized) but not requested in `types`, the clipboard content for the provided type will not be read from the OS clipboard and hence will be unavailable in the clipboard read response.
7878

@@ -104,15 +104,21 @@ const availableTypes = item.types; // ['text/html']
104104
const unsanitizedHtml = await item.getType('text/html');
105105
```
106106

107-
**Example: Default behavior with empty or undefined types**
107+
**Example: When types is undefined or empty**
108108
```js
109109
// Scenario: OS clipboard contains 'text/plain' and 'text/html' data
110-
const items = await navigator.clipboard.read({
110+
111+
// Example 1: Default behavior with no types
112+
const items1 = await navigator.clipboard.read(); // or navigator.clipboard.read({types: undefined});
113+
const item1 = items1[0];
114+
const availableTypes1 = item1.types; // ['text/plain', 'text/html']
115+
116+
// Example 2: Behavior with empty types
117+
const items2 = await navigator.clipboard.read({
111118
types: []
112119
});
113-
114-
const item = items[0];
115-
const availableTypes = item.types; // ['text/plain', 'text/html']. Note all available types are present.
120+
const item2 = items2[0];
121+
const availableTypes2 = item2.types; // []
116122
```
117123

118124
Please refer [Appendix 1](#appendix-1-proposed-idl) for the proposed IDL.
@@ -215,7 +221,9 @@ For developers interested in reproducing these results or running similar benchm
215221
To use live demo, open [this](https://ashishkum-ms.github.io/cr-contributions/sfr/performace_experiment.html) in a browser that supports the Selective Clipboard Format Read.
216222

217223
## References and Acknowledgements
218-
Reference : [Github discussion](https://github.com/w3c/clipboard-apis/issues/191)
224+
References :
225+
- [Github discussion](https://github.com/w3c/clipboard-apis/issues/191)
226+
- [Clipboard APIs spec issue](https://github.com/w3c/clipboard-apis/issues/240)
219227

220228
Many thanks for valuable feedback and advice from:
221229
- [Anupam Snigdha](https://github.com/snianu)

0 commit comments

Comments
 (0)