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