I’ve been trying for 3 days now to write my first addon, a basic hello world type thing. I’ve got zero knowledge of java script or browser addons, but I’ve got plenty of shell scripting experience. This has been way more difficult than I ever thought.
I’m trying to get a very basic demo of a page_action setup for service-now.com. I can get the icon to show up in the URL bar, but I have no idea how to make it do something. For now, I’m just trying to make it log something to the console (ideally I’d love to make some window.alert pop up). This would allow me to start debugging variables and other stuff.
As I understand it, without a popup html, it should just execute something. I put a background script in my manifest, but nothing happens.
Please, can someone just help me figure out how to make the button do something when I click on it. Ideally something that can display output to console or window.alert?
$ cat manifest.json
{
"manifest_version": 2,
"name": "Clippy",
"version": "1.0",
"description": "Copy a HTML link to your clipboard.",
"permissions": [ "clipboardRead","activeTab","tabs" ],
"page_action": {
"browser_style": true,
"default_title": "Clip Me",
"show_matches": ["https://*.service-now.com/*"],
"default_icon": {
"19": "icons/Snow_flake_icon-19.png",
"38": "icons/Snow_flake_icon-38.png"
}
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content-script.js"]
}]
}
$ cat background.js
function MyTest() {
console.log("background2");
window.alert("Test");
}
browser.browserAction.onClicked.addListener(MyTest);