In an attempt to make copy-paste more secure, browsers have mostly limited access to clipboard data so that it is only available during a system copy, cut or paste event. Safari handles image data differently to every other browser for security reasons, so pasting images on Safari sometimes requires dedicated code. There is a way to work around this to get HTML, but you invariably lose information in the process. For example, we have entire libraries dedicated to copy-paste for IE because the only data formats the DataTransfer implementation supports are plain text and URLs. Yet, even then achieving parity is extremely difficult because of just how different the various browsers are. A large portion of the code in Tiny’s PowerPaste plugin is dedicated to dealing with the fact that all the browsers are different (particularly Safari and IE). It probably comes as no surprise to any web developer that all the browsers implement copy-paste differently. As a developer, this makes it restrictive and difficult to work with. It’s not ideal because the API includes attributes that are specific to other uses (like drag and drop) and has not kept up with the way JavaScript and the browsers have changed over the years. The MDN documentation for DataTransfer event only talks about it with regards to Drag and Drop, and not in the context of Clipboard Events. In fact, the format of the data you get from the clipboardData property of ClipboardEvents is a DataTransfer object, which was originally designed for the Drag and Drop API. However, the original Clipboard Event API was created by basing it on other similar APIs - namely, the Drag and Drop API. This is how most of TinyMCE’s clipboard-related functionality works at the moment.
One of the ways to interact with the clipboard in the browser is by looking for cut, copy, and paste events, and overriding or extending the default browser behavior for these events.
There are three main problems with the original copy-paste Clipboard API. It’s not as old as dinosaurs, but it’s almost as old as the physical copier machine and just as clunky. The technology is well overdue for an update. Why copy-paste needs to changeĬopy-paste was always a good idea, but the implementation was lacking. Let’s take a look at some of the biggest copy-paste challenges, how the Clipboard API is changing, and what new features might be possible in the next year or so. As a developer heavily involved in Tiny’s PowerPaste plugin, I’ve done a lot of reading on copy-paste, and in particular, the new Async Clipboard API.Ĭontinuing from our earlier blog about the invention of copy-paste, it’s time to get technical. Although it’s been a fixture of modern computing, the copy-paste function is going through some changes at the moment (at least, the API behind it).