paste data from clipboard using document.execCommand(“paste”); within firefox extension

泄露秘密 提交于 2019-11-28 12:57:01

What you need is not the execCommand but you need to read the data from the clipboard. Your addon is in privelaged scope so you don't need to worry about those preferences. (user.js is firefox-addon right?)

See here:

This way you can read the contents into the var pastedContents.

Here is your example with the above worked in:

var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
trans.addDataFlavor("text/unicode");
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
var pastetextNsiSupports = {};
var pastetextNsiSupportsLength = {};
trans.getTransferData("text/unicode", pastetextNsiSupports, pastetextNsiSupportsLength);

var pastetext = pastetextNsiSupports.value.QueryInterface(Ci.nsISupportsString).data;
 var req = new XMLHttpRequest();
 req.open('POST', pastetext, true);
 req.onreadystatechange = function(aEvt) {
     if (req.readyState == 4) {
         if (req.status == 200)
             dump(req.responseText);
         else
             dump("Error loading page\n");
     }
 };
 req.send(null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!