tomayac / SVGcode

Convert color bitmap images to color SVG vector images.
https://svgco.de
GNU General Public License v2.0
779 stars 117 forks source link

Consider using ClipboardItem.supports to detect if copying SVGs to the clipboard is supported #93

Closed yisibl closed 8 months ago

yisibl commented 8 months ago

I see that currently using userAgent for detection, it would be more ergonomic to use ClipboardItem.supports. Currently, only Chrome supports this API.

https://github.com/tomayac/SVGcode/blob/8371a65aef90b333980baabc425ff02aee32cac0/src/js/clipboard.js#L72-L86

It can be adjusted to:

if (ClipboardItem.supports('image/svg+xml')) {
  // do something
}

My Microsoft partners @snianu and I recently fixed this API's support for image/svg+xml, which has been merged into Chrome 123.0.6298.0.

However, I'm not sure if SVGcode can abandon older versions of Chrome.

tomayac commented 8 months ago

Thanks for the suggestion. I think the way I use it now as a progressive enhancement should work:

if (
  ('supports' in ClipboardItem &&
    ClipboardItem.supports('image/svg+xml')) ||
  !IS_SAFARI
) { /* … */ }

Once browser support is better, the UA sniffing part can go, too.