I am trying to use navigator.clipboard.write(blob)
to copy a DOMString to the clipboard. I am able to use clipboard.writeText('text')
and have it copy, but I am needing text/html.
Example that is failing:
const copy = async () => {
await navigator.permissions.query({name: "clipboard-write"}).then(result => {
if (result.state == "granted" || result.state == "prompt") {
const data = new Blob(['<div>test</div>'], {type : 'text/html'})
navigator.clipboard.write(data);
}
})}
When I run it, I get the following error:
Uncaught (in promise) TypeError: Failed to execute 'write' on 'Clipboard': Iterator getter is not callable.
I have also tried changing text/html to text/plain, which I thought would make it function the same as writeText but did not.
I then attempted wrapping the blob in a new ClipboardItem which I found from a another question:
const data = new Blob(['<div>test</div>'], {type: 'text/html'})
const item = new ClipboardItem({'text/html': data});
navigator.clipboard.write(item);
Any guidance would be appreciated.
text/html
works as of Chrome (95.0.4638.69) – Laguna