[clipboard events] implicitly prevent default event action?

Hi,
there's a very annoying gotcha in the clipboard events spec: the "default action" of for example the copy event is to copy any selected text in the page (and do nothing if there is no selection). This remains the default action even if you use event.clipboardData.setData() and friends to modify the "payload" - it's a requirement to also call event.preventDefault() to make what you want to happen actually happen.

This extra "event.preventDefault()" is something I've personally forgotten to do several times - which is a bit embarrassing as I should be expected to know :-p. But worse than that is that regular web developers are likely to run into this pretty often too. I guess lots of people will struggle a bit here, and few of them will understand why it is even necessary.

So, is it necessary? IMO we can't change this basic default-action-of-event-is-copying-content approach, for backwards compatibility. But I guess we could say that the implementation itself cancels the default event if 

a) The event is script-generated and has a data payload (new ClipboardEvent('copy', {dataType:'text/plain', data:'Hi World'}))
b) Any event listener calls setData() or modifies the DataTransfer payload some other way

Thoughts?
-Hallvord

Received on Monday, 19 May 2014 13:51:03 UTC