Placing a variable’s content into the clipboard on chrome or opera is described here
In these browser, it can be done from a background script, and for a user, the textarea is not visible.
To my understanding, this must be done in a content script in Firefox.
I tried the following code in a content script
//request.data is the value I want to place in the clipboard
var ta = document.getElementById(‘filteredClipboard_data’);
if( ta == null){
ta = document.createElement(‘textarea’);
ta.contentEditable = “true”;
//ta.hidden = “true”;
ta.id = ‘filteredClipboard_data’;
document.body.appendChild(ta);
} else {
console.log(“found ta”);
}
ta.value = request.data;
ta.select();
document.execCommand("Copy");
The copy command works, but my problem is that with ff53 the browser scroll down at the bottom of the page where the textarea is plain visible. This is not the case with nigthly. The code works.
Adding ta.hidden = true
fails in both version: it's the selected text that is copied and not the the string received from the background script.
Please note: starting the add-on with
web-ext run --firefox=“C:\Program Files\Nightly\firefox.exe”
does not work: it seems that the content script is not reached. I received the error “Error: Could not establish connection. Receiving end does not exist”. I have to pack the add-on and drag it on the extension page to get it work correctly.
François