[w3c/clipboard-apis] Arbitrary clipboard types (Issue #165)

As the current async clipboard API does not have a definition, extensions to it are somewhat hard to define, but here is my basic idea for arbitrary clipboard types that I think works for all parties.

The `ClipboardItem` constructor and the `ClipboardItem` `getType()` method both take a string that represents a type. As this type is a MIME type it's formatted as "`type/subtype`". The only types supported there are builtin types, such as "`text/plain`".

To extend this to allow arbitrary types, without impacting the processing of builtin types, which can be special depending on the user agent and its requirements, this proposal suggests introducing a namespace for arbitrary types. Arbitrary types will always have their data stored and read as-is, without any manipulation.

Arbitrary types are denoted by the prefix "`web `" ("`web`" followed by U+0020 SPACE) to distinguish them from builtin types. They are stored in an implementation-defined manner on the underlying OS clipboard and must not interfere with builtin types.

Expressed in JavaScript, this is how would you read an arbitrary type:

```js
const items = await navigator.clipboard.read();
const arbitraryBlob = await items[0].getType(`web ${arbitraryType}`);
```

And this is how would write one:

```js
const items = [new ClipboardItem({ `web {$arbitraryType}`: arbitraryBlob })];
navigator.clipboard.write(items);
```

@whsieh @snianu @BoCupp-Microsoft @travisleithead @johanneswilm

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/clipboard-apis/issues/165
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/clipboard-apis/issues/165@github.com>

Received on Friday, 28 January 2022 10:08:32 UTC