My goal is to make an extension for myself(and hopefully others) that adds a more left-handed user friendly copy link address keybind(Y or A) for Microsoft Edge. But as stated navigator.clipboard.writeText() fails without any meaningful indicator to the problem and nothing is copied to system clipboard.
Environment:
The JS code:
const CONTEXT_MENU_ID = "MY_COPY_LINK";
async function copyLink(info, tab) {
if (info.menuItemId !== CONTEXT_MENU_ID) {
return;
}
var urlToCopy = info.linkUrl;
console.log(urlToCopy + " was copied.");
if(navigator.clipboard) {
navigator.clipboard.writeText(urlToCopy).then(function() {
/* clipboard successfully set */
console.log("success");
}, function() {
/* clipboard write failed */
console.log("failed");
});
}
else {
console.log("clipboard undefined");
}
}
chrome.contextMenus.create({
title: "Cop&y Link Address",
contexts:["link"],
id: CONTEXT_MENU_ID
});
chrome.contextMenus.onClicked.addListener(copyLink)
Manifest file:
{
"manifest_version": 2,
"name": "copylinkaddress",
"version": "1",
"permissions": ["contextMenus","clipboardWrite"],
"background": {
"scripts": ["background.js"],
"persistent": true
}
}
I've tried using write() only with a text/plain ClipboardItem but same result, it just fails.