felixfbecker / svg-screenshots

📸🧩 Browser extension to take scalable, semantic, accessible screenshots of websites in SVG format.
809 stars 29 forks source link

Reusing the Async Clipboard API to Copy SVGs #122

Open yisibl opened 5 months ago

yisibl commented 5 months ago

Chrome is working on improving the ability to copy SVG to the clipboard, can you reuse the Async Clipboard API and add image/svg+xml? We need to test that it doesn't crash before shipping.

https://github.com/felixfbecker/svg-screenshots/commit/961256599ec8b1098fb7df898b0b7a728dfaef9c

await navigator.clipboard.writeText(svgString)
// const plainTextBlob = new Blob([svgString], { type: 'text/plain' })
// Copying image/svg+xml is not yet supported in Chrome and crashes the tab
// await navigator.clipboard.write([
//  new ClipboardItem({
//    [blob.type]: blob,
//    'text/plain': plainTextBlob,
//  }),
// ])

Now you can use ClipboardItem.supports('image/svg+xml') to detect if SVG is supported.