I am trying to read clipboard contents upon a context menu click, and I have a bare bones menu system to do this, but it does not read any information
Here is the menu item:
browser.contextMenus.create({
id: "clipboard",
title: " Check Clipboard",
contexts: ["all"]
}, onCreated);
It calls a switch:
browser.contextMenus.onClicked.addListener((info, tab) => {
switch (info.menuItemId) {
case "clipboard":
checkclip();
break;
}
});
This calls a function, which should pull the contents of the clipboard, but it doesn’t:
function checkclip(){
bg = browser.extension.getBackgroundPage(); // get the background page
bg.document.body.innerHTML= ""; // clear the background page
// add a DIV, contentEditable=true, to accept the paste action
var helperdiv = bg.document.createElement("div");
document.body.appendChild(helperdiv);
helperdiv.contentEditable = true;
// focus the helper div's content
var range = document.createRange();
range.selectNode(helperdiv);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
helperdiv.focus();
Unfortunately, this is what I get on the console:
focus on: #document id: undefined content_script.js:18:7
focus on: TEXTAREA id: message content_script.js:18:7
Check read clipboard: context_menu.js:36:1
So, the function runs, but does not get the contents of the clipboard.
This is a crucial functionality of the addon that I am trying to recreate with Webextensions.