I'm trying to make my first WebExtension (a button on toolbar) to copy the current URL to clipboard. What should I add to background.js?
I have this manifest.json file:
{
"manifest_version": 2,
"name": "Copy URL to Clipboard",
"description": "desc",
"version": "1.0",
"homepage_url": "",
"icons": {
"48": "icons/clipboard-48.png"
},
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": {
"16": "icons/clipboard-16.png",
"32": "icons/clipboard-32.png"
}
}
}
I tried something like this but it doesn't work:
function copyURL() {
var url = document.location.href;
url.select();
document.execCommand("Copy");
}
browser.browserAction.onClicked.addListener(copyURL);