Unable to copy image to clipboard in Firefox Addon development

I am developing a Firefox Addon that has this feature for copying an image to the clipboard. I am using require ("sdk / clipboard") lib as described in the documentation

But when I try to mount a base64 image, it causes the following error:

JPM [error]   Message: Error: Invalid flavor for image/jpg

You can find an example of a command that tries to copy the image to the clipboard and gives me an error here: https://jsfiddle.net/g0Lff2b5/

When I try to use this example on a website, it works. I think that maybe my base64 is invalid, although I used a lot of base64 generators, and setting this base64 to the tag works fine.

Obsessions?

+4
source share
1 answer

Well, I made a fix that solves now, but the main problem remains.

What I did to copy the image to the clipboard was to create a canvas object, add an image to it and call a function that converts the image to a BASE64 string (.toDataURL ('image / png')). then I was able to copy this base64 to the clipboard.

+3
source

Source: https://habr.com/ru/post/1610513/