Missing Context menus (mv3)

Hi everyone.

I have an issue with the context menus created by me extension (manifest v3). Sometimes they just disappear. I found the workaround - manually trigger (e.g. disabling and enabling the extension) a service worker which recreates the context menus. How can I fix it?

Manifest file: https://github.com/ovarn/find-it/blob/3d8bf194d5ccb3f06108fc9dd18dd62b6e70bd44/manifest.json
Service Worker: https://github.com/ovarn/find-it/blob/3d8bf194d5ccb3f06108fc9dd18dd62b6e70bd44/background.js

Thank you for any help!

Can you see some pattern in the disappearance? After starting browser, updating addon, while using addon, etc…
That would help narrow the search.

Wile I was checking your code, I’ve noticed some things…:

  1. this whole file: https://github.com/ovarn/find-it/blob/3d8bf194d5ccb3f06108fc9dd18dd62b6e70bd44/js/removeAllContextMenus.js
    can be simplified to “chrome.contextMenus.removeAll()” - it already returns a Promise (in Firefox and Chrome) if you don’t supply a callback function.

  2. if your callback doesn’t use any parameters, you can just pass it by name, for example:

// instead of this:
chrome.runtime.onInstalled.addListener((details) => {
	createContextMenus();
});
// you can use this:
chrome.runtime.onInstalled.addListener(createContextMenus);
  1. your background script is defined using a “page” property, I don’t think this is compatible with Chrome. To support both - Firefox and Chrome, you’ll need to use " scripts" and " service_worker" properties, more info: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background#browser_support

I’ve installed your extension as a temporary add-on in Firefox 127.0.2 running in Linux Mint, but I can’t reproduce the bug.

What version of Firefox are you using, and how did you install the extension?

Can you see some pattern in the disappearance?

Nope. Sometimes it happens once a week, sometimes even less often.

  1. Thanks for letting me know.
  2. Yes, I know that. I believe I did it because I wanted to use it (details param) in the future releases.
  3. I don’t use Chrome to be honest, but I test the extension in Chromium browsers and looks like it works there: https://chromewebstore.google.com/detail/find-it/bpghchbjndmjpljndpbbfppgnaglbfdd. But maybe you are right and I need to play with this property value.
    UPD: I forget to say that there is a different manifest file for the Chromium based browsers: https://github.com/ovarn/find-it/blob/3d8bf194d5ccb3f06108fc9dd18dd62b6e70bd44/manifest-chrome.json

Thanks for the shared knowledge!

Hi hans_squared,

I can’t reproduce the bug.

Yes, it’s hard to reproduce. Sometimes they disappear week after I re-trigger the service worker.

What version of Firefox are you using

127.0.2 (64-bit) Ubuntu (snap version)

how did you install the extension?

From the store: https://addons.mozilla.org/en-GB/firefox/addon/find-it-ext/

Known issue.
Fixed in Firefox 128
1771328 - Restarting manifest v3 extension removes its context menu entry

2 Likes

Good find!
Note that even though he is re-creating the menus every time the background script is running, it won’t work if the script doesn’t run, which should be on browser start!

I have a feeling, on startup, browser will execute background scripts only if:

  • it’s persistent background script
  • it has a runtime.onStartup listener

Anyway, the 128 version should start rollout tomorrow, so this is a bug that will fix itself :slight_smile:.

1 Like

Good to know. Thank you very much!