Search code examples
firefoxfirefox-addonfirefox-addon-sdkfirefox-developer-tools

Unable to copy image to clipboard in Firefox Addon development


I'm developing a Firefox Addon which has this functionality to copy an image to clipboard. I'm using require("sdk/clipboard") lib, as described in the documentation

But when I try to attach a base64 image, it gives me the following error:

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

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

When I try to use the example in the website, it works. I think that perhaps my base64 is invalid, even though I used many base64 generators, and setting this base64 into a tag works fine.

Anly ideas?


Solution

  • Well, I did a workaround fix that solves for now, but the main problem remain.

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