# Context menu not printing anything to the console

**URL:** <https://discourse.mozilla.org/t/context-menu-not-printing-anything-to-the-console/124258>\
**Category:** Development\
**Tags:** learning, issue\
**Created:** [November 14, 2023, 12:26pm UTC](https://discourse.mozilla.org/t/context-menu-not-printing-anything-to-the-console/124258 "2023-11-14T12:26:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spifory](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/spifory/32/63928_2.png) [@spifory](https://discourse.mozilla.org/u/spifory)\
**Post date:** [November 14, 2023, 12:26pm UTC](https://discourse.mozilla.org/t/context-menu-not-printing-anything-to-the-console/124258/1 "2023-11-14T12:26:01Z")

</div>

I have an addon that is meant to just print out “hi!” when a link is right-clicked (and the menu optional is clicked). However for some reason it seems to not print anything, both in the Browser Console, and the actual tab’s console (Ctrl + Shift + I)

```auto
// manifest.json
{
  "manifest_version": 2,
  "name": "hello-world",
  "version": "1.0.0",
  "description": "The addon that does jack sh*t!",
  "permissions": [
    "contextMenus"
  ],
  "background": {
    "scripts": [
      "./background.js"
    ]
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ]
    }
  ]
}

```

```auto
// background.js
const MENU_ID = 'thing-e-roo';

browser.contextMenus.create({
    id: MENU_ID,
    title: 'Perform a useless console log',
    contexts: ['link']
})

browser.contextMenus.onClicked.addListener((info, tab) => {
    if (info.menuItemId === MENU_ID) {
        console.log('hi!')
    }
})

```

This is the code, and it’s meant to just print “hi!” when the option is clicked. I’ve tried it without the condition, tried using `alert` instead and still seems to not do anything, so I’m kind of unsure what to do at this point

Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [November 14, 2023, 12:44pm UTC](https://discourse.mozilla.org/t/context-menu-not-printing-anything-to-the-console/124258/2 "2023-11-14T12:44:47Z")

</div>

I think you are looking at the wrong console, try to put console log in your background script when it executes first time to see if you can actually see it 🙂.

In any case, what you want is to open:  
about:debugging#/runtime/this-firefox

And then click “Inspect” button.

Or use the `web-ext` tool, it can now open it for you on start:

```auto
web-ext run --devtools

```

---

<div class="post-metadata">

**Author:** ![spifory](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/spifory/32/63928_2.png) [@spifory](https://discourse.mozilla.org/u/spifory)\
**Post date:** [November 14, 2023, 1:08pm UTC](https://discourse.mozilla.org/t/context-menu-not-printing-anything-to-the-console/124258/3 "2023-11-14T13:08:38Z")

</div>

Oh, huh, you’re right, this was the wrong console 😅  
In that case, how do I get it to print something in the console of the tab where the menu is used? Like if I use it on YouTube, for example, then it should show on that tab’s console  
Or is it doing this because I’m using it in `about:debugging`, and it’s because it’s not an actual addon?

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [November 14, 2023, 1:17pm UTC](https://discourse.mozilla.org/t/context-menu-not-printing-anything-to-the-console/124258/4 "2023-11-14T13:17:53Z")

</div>

The background script is basically an invisible page loaded in the background, so whatever runs there is not visible in other consoles.  
See also:

> **[Anatomy of an extension - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Anatomy_of_a_WebExtension)**
>
> An extension consists of a collection of files, packaged for distribution and installation. In this article, we will quickly go through the files that might be present in an extension.

If you want to print something into the console in a specific tab, then your script needs to run inside that tab.

So if you want to see it on the YouTube page, you need to run script in the YouTube page. For example by injecting a content script there (you already have “content\_scripts” in your manifest file, although you are not loading any file yet.
