navigator.clipboard.writeText on non SSL (http: as opposed to https:) site

(Matthew G. Saroff) #1

I am looking to use navigator.clipboard.write &

I was having some issues, and I realized that it was not working because the site I was trying it on did not use SSL: It was an http:// site, not an https:// site, and so the API was not activated.

Is there a way to activate this on non SSL pages, and if so, what are the ancillary isues, particularly with regard to security, that this would bring up.

All actions on the addon are user initiated, through the context menu, so there is no way that this addon would paste something to, or copy something from a page, without user actions.


(Martin Giger) #2

As far as I understand, as long as you have the related clipboard permissions and are calling the functions in your extension contexts and not in a page context they should work just fine.


(Matthew G. Saroff) #3

I’m unclear on how to handle contexts.

I have a web page that can be loaded either with or without SSL, or which gives me use cases to test, and the document.execCommand('paste') command only works on the SSL page.

It pasts a string (“blblblblblbl”) over a selection, but it only works on a page with SSL.

Code from the content script below:

console.log("Current contents of clipboard",(await readFromClipboard()));
document.execCommand('cut'); //copy to clipboard
let copsel = await readFromClipboard();
console.log("selection copied to clipboard", copsel);
await navigator.clipboard.writeText('blblblblblblblblblblblblblbl'); // this is what appears not to be activating

(Matthew G. Saroff) #4

It appears that it is both the navigator.clipboard.writeText and the document.execCommand(‘paste’) in http mode, though they do in https mode.

I am wondering if there is a work around.

If not, I end up with some code bloat to accommodate most, but not all, of the cases.

Update, it’s just the navigator.clipboard.writeText, document.execCommand('paste') works fine.