I am trying to paste clipboard data into a variable that gets fed into and fired via XMLhttprequest POST message.
I have created a firefox user.js with this code to
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);