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

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)

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 :slight_smile:

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

2 Likes

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:

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!

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.

3 Likes