# How to test & debug what happens on browser quit and restart

**URL:** <https://discourse.mozilla.org/t/how-to-test-debug-what-happens-on-browser-quit-and-restart/136864>\
**Category:** Add-on Support\
**Created:** [October 31, 2024, 9:25pm UTC](https://discourse.mozilla.org/t/how-to-test-debug-what-happens-on-browser-quit-and-restart/136864 "2024-10-31T21:25:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluelemon](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/bluelemon/32/77685_2.png) [@bluelemon](https://discourse.mozilla.org/u/bluelemon)\
**Post date:** [October 31, 2024, 9:25pm UTC](https://discourse.mozilla.org/t/how-to-test-debug-what-happens-on-browser-quit-and-restart/136864/1 "2024-10-31T21:25:24Z")

</div>

I noticed that my extension, when installed from AMO, disappears from the context menu when I restart the browser.

How can I debug this behaviour? (If I load the extension temporaily for debugging purposes, then it will automatically be removed after restarting Firefox)

---

<div class="post-metadata">

**Author:** ![stig](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/stig/32/24662_2.png) [@stig](https://discourse.mozilla.org/u/stig)\
**Post date:** [November 1, 2024, 8:51am UTC](https://discourse.mozilla.org/t/how-to-test-debug-what-happens-on-browser-quit-and-restart/136864/2 "2024-11-01T08:51:14Z")

</div>

There’s some setting (via about:config) in Firefox Developers Edition making it possible to install your local version permanently. I don’t remember details right now, and I’m not in general the expert regarding debugging webextensions.

Just want to mention that there’s been a lot of bugs regarding context-menu items disappearing in different situations (some fixed now, some not), so while it in principle it shouldn’t be needed, I have ended up pretty aggressively redefining my menu items. Currently I (re)define my menu items both on onInstalled and onStartup plus a scenario where I have detected that my extension probably was allowed to run in private mode under installation (the latter should be fixed in Firefox 128 or 129). Yes sounds like there are several cases I’m doing it double, but got so tired of getting reports of missing menu items in my extension.

Maybe it would be simpler to just always (re)define menu-item in “top level” of backgroundscript, so it happens every time backgroundscript runs. Got to clean up my messy code around this some day 🙂

Some related bugs/links (I remember it like there was more bugs than this, but those I still refer to in comments in my extension code):

> **[1817287 - browser.runtime.onInstalled event not fired when disabled add-on is...](https://bugzilla.mozilla.org/show_bug.cgi?id=1817287)**
>
> NEW (nobody) in WebExtensions - Frontend. Last updated 2024-02-18.

> **[1771328 - Restarting manifest v3 extension removes its context menu entry](https://bugzilla.mozilla.org/show_bug.cgi?id=1771328)**
>
> RESOLVED (lgreco) in WebExtensions - General. Last updated 2024-06-11.

> [@Strange MV3 behaviour - browser.runtime.onInstalled event and menus.create](https://discourse.mozilla.org/t/strange-mv3-behaviour-browser-runtime-oninstalled-event-and-menus-create/111208):
>
> When you place menu creation in a runtime.onInstalled listener using menus.create , as recommended by the docs, it works as expected initially. However, if you disable and re-enable the extension, the item disappears from the context menu. Here is the sample code: browser.runtime.onInstalled.addListener(() =\> { browser.menus.create({ id: "someId", title: "Some title", contexts: ["image"], }); }); Is this an MV3 issue? If so, is there a way to bypass it? Thank you!

---

<div class="post-metadata">

**Author:** ![bluelemon](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/bluelemon/32/77685_2.png) [@bluelemon](https://discourse.mozilla.org/u/bluelemon)\
**Post date:** [November 1, 2024, 11:20am UTC](https://discourse.mozilla.org/t/how-to-test-debug-what-happens-on-browser-quit-and-restart/136864/3 "2024-11-01T11:20:54Z")

</div>

Thanks for your help Stig. I had no idea that this issue had been already raised in Feb’2023. I experienced this issue starting with Firefox Dev Edition 132, and it still is present in 133.0b2 (64-bit). My extension uses MV2, so it’s not just MV3 that is a problem.

I found some info detailing how to make a locally installed add-on permanent. Unfortunately, Mozilla have broken things again in 2023 and it doesn’t work any more:

> **[Installing unsigned extensions permanently to Firefox Developer edition](https://wiringbits.net/browser-extensions/2020/11/27/installing-unsigned-extensions-permanently-to-firefox.html)**
>
> If you have worked with browser extension on Firefox, you likely go to about:debugging for installing the extensions temporary, while useful for development, the extension gets removed once Firefox restarts.

Regarding building the context menu in browser.runtime.onInstalled.addListener, my extension already did that as I was calling an init() function which itself called a buildContextMenu() function:

```
browser.runtime.onInstalled.addListener(async (details) => {
    if (details.temporary) {
        logToConsole = true;
    } else {
        logToConsole = false;
    }
    if (logToConsole) {
        console.log('Debugging enabled.');
        console.log(details);
    }
    if (details.reason === "install" || details.reason === "update") {
        await init();
    }
})

```

UPDATE: I’ve just tested with Firefox 129.0.2 and the problem is already there, so it doesn’t seem to be related to the latest Firefox updates. It’s really annoying that I can’t debug this issue by installing the extension locally permanently. It forces me to publish the extension to AMO to be able to debug. That’s really bad!

---

<div class="post-metadata">

**Author:** ![bluelemon](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/bluelemon/32/77685_2.png) [@bluelemon](https://discourse.mozilla.org/u/bluelemon)\
**Post date:** [November 5, 2024, 5:28pm UTC](https://discourse.mozilla.org/t/how-to-test-debug-what-happens-on-browser-quit-and-restart/136864/4 "2024-11-05T17:28:41Z")

</div>

I was able to solve my disappearing extension from the context menu by using runtime.onStartup. Thank you for forwarding, @stig. Thank you for the tip, @juraj.masiar.
