Help with some basic Hello World stuff

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);

Hello,
First of all, make sure to read the Anatomy of the web-extensions:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Anatomy_of_a_WebExtension
It explains what background script is and how it differs from content-script (which is what you actually want and what is actually running in a page).

What you want to do is execute browser.tabs.executeScript() from your background script. There are some example addons in the docs as well:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript