Post e10s, this seems to be the most consistent way (should work in both pre and post-e10s builds):
const tabs = require("sdk/tabs");
function getSelectedText() {
return new Promise(function (resolve, reject) {
tabs.activeTab.attach({
contentScript: "self.postMessage(String(getSelection()));",
onMessage: resolve,
onError: reject,
});
});
}
Then you can use it pretty simply:
getSelectedText().then(text => {
console.info("SELECTED TEXT =>", text);
});
Hello. I am trying for more than 3 weeks to get the selected text in Firefox. Can you explain me how to use this. Thanks