clipboard-apis icon indicating copy to clipboard operation
clipboard-apis copied to clipboard

Does write() take ClipboardItem or ClipboardItems?

Open lgarron opened this issue 5 years ago • 8 comments

The IDL specifies that write() takes ClipboardItems, but all the examples I've seen take a single ClipboardItem.

lgarron avatar Aug 12 '19 18:08 lgarron

Related to this: why do read()/write() take/return multiple ClipboardItems, when each ClipboardItem may contain may contain multiple types?

Shouldn't either exactly one ClipboardItem with multiple types or multiple ClipboardItems with each having one type suffice? If not, it should be possible to provide use-cases.

mbrodesser avatar Jun 02 '21 10:06 mbrodesser

What do Chrome/Safari do here?

@evilpie did you run into this?

annevk avatar Jun 02 '21 11:06 annevk

More research about the issue lead to https://blog.tomayac.com/2020/03/20/multi-mime-type-copying-with-the-async-clipboard-api/#copying-an-image, which links to https://support.microsoft.com/en-us/topic/copy-and-paste-using-the-office-clipboard-714a72af-1ad4-450f-8708-c2931e73ec8a?ui=en-us&rs=en-us&ad=us#ID0EAABAAA=Windows. Apparently, Microsoft Office indeed supports multiple clipboard items (up to 24). So I guess a future use-case could be copy-pasting from Microsoft Office to Office 365, that is, to the browser.

So it seems this ticket can be closed. It could be worth mentioning this use-case in the spec, though.

mbrodesser avatar Jun 02 '21 13:06 mbrodesser

I think the issue in OP remains, no? That article also mentions that implementations might not do this?

annevk avatar Jun 02 '21 17:06 annevk

Chrome (and Firefox, because there is no spec ..) only allows a single ClipboardItem to be passed to write. A zero length array will silently do nothing.

evilpie avatar Jun 02 '21 17:06 evilpie

I think the issue in OP remains, no? That article also mentions that implementations might not do this?

Yes. Blink's idl interface takes multiple ClipboardItems, but throws an exception if multiple items are received.

If the use case given in above comment is invalid, then indeed taking only one ClipboardItem would be simpler and hence preferable.

@gked: since you're working for Microsoft, can you please shed some light on this?

mbrodesser avatar Jun 03 '21 08:06 mbrodesser

Copying multiple items where each item has multiple representation is a thing in iOS & iPadOS. e.g. you can select multiple images in Photos and copy them over to Notes and paste them all. WebKit supports this capability for both reading & writing.

rniwa avatar Jun 03 '21 09:06 rniwa

Copying multiple items where each item has multiple representation is a thing in iOS & iPadOS. e.g. you can select multiple images in Photos and copy them over to Notes and paste them all. WebKit supports this capability for both reading & writing.

Thanks, that's helpful to know. So multiple ClipboardItems are needed. I suggest adding the iOS/iPadOS use case to the spec. Otherwise, this question might arise again.

Since there are operating systems, e.g. Ubuntu, that support multiple clipboards, it seems the spec should state that ClipboardItems should stem from exactly one of them. But this should be dealt with in a separate ticket.

mbrodesser avatar Jun 11 '21 13:06 mbrodesser