JSFiddle - React, Tailwind, and code Playground
by murkle
HTML
The new Clipboard API for Images is <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=150835#c118">enabled by default from <b>Chrome 76</b></a>. If you are on Chrome 75 then you need to enable this flag chrome://flags/#enable-experimental-web-platform-features
<p/>
Press button to copy a test png to the clipboard. <Ctrl>V to paste an image or text
<button id="copyimage">Copy Image</button>
<p>
<p>Also right-click -> "Copy Image" for these images to test (jpeg & gif, but will be pasted as png):
<p>
<p>
For mobile:
<p>
<button id="pasteimage">Paste Image</button>
<textarea>for mobile, focus here then paste</textarea>
JavaScript
if (typeof ClipboardItem != "function") {
alert("new clipboard not supported in this Browser. Please upgrade to Chrome 76 or enable chrome://flags/#enable-experimental-web-platform-features");
}
function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
// create a view into the buffer
var ia = new Uint8Array(ab);
// set the bytes of the buffer to the correct values
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ab], {type: mimeString});
return blob;
}
var textHTML =...