Does Safari's clipboardData actually work?

I’ve been playing around with the clipboardData object in Internet Explorer and Safari all weekend. IE’s access is pretty straightforward, the object is located on window and always available. Safari adds clipboardData to the event object, but only during clipboard events. You can only read clipboard data in Safari in an onpaste event handler, but it’s unclear when, if ever, you can set data to the clipboard. I’ve tried several things and haven’t successfully been able to get data onto the clipboard.

Since clipboardData is only available during clipboard events, that means you can only use it in response to the user initiating one of these events and not in response to any other user action. I’ve tried overriding the cut and copy events, trying to set the clipboard data myself and using preventDefault() to cancel the default behavior, but this doesn’t work.

I took a quick look at the source code and it looks like perhaps this feature just isn’t enabled. It seems that the types property hasn’t been implemented either, even though the documentation says it should be there. The setData() method just returns false every time, I’ve tried using “text”, “Text”, and “text/plain” as the first argument but it doesn’t seem to matter. Has anyone been able to set data onto the clipboard in Safari?

Understanding JavaScript Promises E-book Cover

Demystify JavaScript promises with the e-book that explains not just concepts, but also real-world uses of promises.

Download the Free E-book!

The community edition of Understanding JavaScript Promises is a free download that arrives in minutes.