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

Firefox with `ClipboardItem` enabled copies `[object Promise]` #90

Closed silverwind closed 1 year ago

silverwind commented 1 year ago

To reproduce:

I'm not sure where this goes wrong, but I suspect it has something to do with the user agent sniffing. I'm using this same API in this module, so I think it is operational and the bug is from this app code, not from Firefox.

tomayac commented 1 year ago

This is the relevant code: https://github.com/tomayac/SVGcode/blob/80bc0bdc1e2a93ec3b022ebffbc0038a1714f8a1/src/js/clipboard.js#L65. What operating system does this happen on?

silverwind commented 1 year ago

MacOS, window.ClipboardItem does exist with the about:config preference enabled. So I think it ends in this branch:


await navigator.clipboard.write([
  new ClipboardItem({
    'text/plain': new Promise(async (resolve) => {
      resolve(new Blob([svg], { type: 'text/plain' }));
    }),
  }),
]);
tomayac commented 1 year ago

Thanks for the report. I will take a look soon.

silverwind commented 1 year ago

I think the likely fix will be to remove the Promise wrapping. I tested the API with non-promise and Safari copied it fine. The fact that it works with Promise in Safari while not in Firefox is likely an implementation difference between the two.

tomayac commented 1 year ago

Fixed via https://github.com/tomayac/SVGcode/commit/4a2234480c6b2105577310e90b7da7d0ae80c127. Thanks for reporting!

silverwind commented 1 year ago

Thanks, confirmed working!