I am building a xpcom component with JS. I have got the clipboard data in JS, when the data type is image/png, I want to get its base64 string, my code is:

        ......
        trans.addDataFlavor('image/png');
        clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
        trans.getTransferData('image/png', str, strLength);
        let mw = Services.wm.getMostRecentWindow("navigator:browser");

        data.data = str.value.QueryInterface(Ci.nsISupportsCString).data;
        data.data = mw.btoa(data.data);
        ...

I can get the base64 string under Linux, but when I run my code in windows, I got an error: NS_NOINTERFACE: Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsISupports.QueryInterface]

data.data = str.value.QueryInterface(Ci.nsISupportsCString).data; I do not konw how the get the base64 string of the image data in my xpcom component, who can give me an answer?

有帮助吗?

解决方案

Apparently images are stored to clipboard differently across platforms. Check how Jetpack reads them.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top