I tried to store canvas blob into navigator clipboard
graphicDiv.addEventListener(
'click',
(event) => {
const canvas = <HTMLCanvasElement> document.getElementById('canvas');
canvas.toBlob((blob) => {
if (blob) {
let data = [new ClipboardItem({ [blob.type]: blob })];
navigator.clipboard.write(data).then(
function () {},
function (err) {}
);
}
});
},
false
);
it seems something is wrong since TS gives me errors as follow
Argument of type '{ [x: string]: Blob; }' is not assignable to parameter of type 'Record<string, ClipboardItemData>'.
'string' index signatures are incompatible.
Type 'Blob' is missing the following properties from type 'Promise<ClipboardItemDataType>
error TS2339: Property 'write' does not exist on type 'Clipboard'.
102 let data = [new ClipboardItem({ [blob.type]: blob })];
~~~~~
is there any one familier with how to store canvas chartjs chart into the clipboard?
https://www.w3.org/TR/clipboard-apis/#typedefdef-clipboarditemdata 6.4.2. Writing to the clipboard
These data types must be placed on the clipboard with a corresponding native type description if added to a DataTransfer object during copy and cut events.
text/plain
text/uri-list
text/csv
text/html
image/svg+xml
application/xml, text/xml
application/json