5

Is it possible to put binary data in the clipboard with a specific data flavor? Even a subset of browsers with hacks is okay.

In this case, the specific goal is copying an Office object, which is a ZIP file containing XML and other embedded files, with data flavor GVML (Office clipboard format)

The answers I can find indicate text is text is definitely possible. Posts about binary are mostly about images, which is also kind of possible. But I don't see anything about other data flavors.

UPDATE

It appears that this may not be possible. The following code runs in Chrome 51, Firefox 46 and Safari 9.0, and is triggered by a Cmd/Ctrl+C keyboard event.

  • Firefox copies only text and html to clipboard
  • Chromium copies <b>Hello binary!</b> but as data flavor org.chromium.web-custom-data and embeds the custom/binary in zero-padded hexadecimal in the text.
  • Safari copies <b>Hello binary</b> as data flavor dyn.ah62d4rv4gu81k3p2su10e4psqf3hw and does not include custom/binary at all.

document.addEventListener('copy', function(e){ e.clipboardData.setData('text/plain', 'Hello, world!'); e.clipboardData.setData('text/html', '<b>Hello, html!</b>'); e.clipboardData.setData('custom/binary', '<b>Hello, binary!</b>'); e.preventDefault(); });

Above code from "Example 1" at https://www.w3.org/TR/clipboard-apis/

How do I copy to the clipboard in JavaScript?

https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript/

Community
  • 1
  • 1
prototype
  • 6,440
  • 12
  • 48
  • 86
  • Sounds like there is something in the works for Chromium. https://www.chromestory.com/2019/12/raw-clipboard-access/ – Moss Feb 22 '20 at 21:40

0 Answers0