browser.runtime.onInstalled event not fired when disabled add-on is re-enabled, and menus.create registration disappeared
Categories
(WebExtensions :: Frontend, defect, P2)
Tracking
(firefox110 affected, firefox111 affected, firefox112 affected)
People
(Reporter: mb, Unassigned)
References
(Depends on 1 open bug)
Details
Attachments
(1 file)
|
718 bytes,
application/zip
|
Details |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/110.0
Steps to reproduce:
When you place menu creation in a runtime.onInstalled listner 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"],
});
});
Actual results:
Menu item disappears from the context menu.
Expected results:
The menu item should continue to appear in the context menu after the extension is disabled and re-enabled.
Comment 1•2 years ago
|
||
Hello mb,
Would you mind attaching a test extension?
I’m from Webextensions QA and I did try to build an extension using the example code you provided, but for some reason I could not get the extension to show the menu item in the context menu.
Thank you !
Comment 2•2 years ago
|
||
Confirmed.
STR:
- Load attached extension at
about:debugging(or: rename .zip to .xpi, setxpinstall.signatures.requiredto false (Nightly only - not release!) and open the xpi from the location bar to install it) - Right-click anywhere to see the new "Menus created at onInstalled" menu item
- Visit about:addons and disable then re-enable the add-on,
- Right-click anywhere again and look for the menu item.
Expected:
- The menu item re-appears
Actual:
- No menu item any more
Extra info:
- Works in Chrome
Comment 3•2 years ago
|
||
This happens because Firefox deletes the underlying data when the add-on is disabled (source.
We could consider fixing this by triggering onInstalled when an add-on is re-enabled.
That behavior (of onInstalled) has been requested a few days ago at https://github.com/w3c/webextensions/issues/353
Comment 4•2 years ago
|
||
There are two ways to fix this:
- Supporting
onInstalledat enable as suggested in comment 3. - Not removing the data (the approach from bug 1771328, which is similar to this bug - menus disappear when extension is reloaded).
Comment 5•2 years ago
|
||
Also confirmed based on the STR from Comment 2.
Reproduced on the latest Nightly (112.0a1/20230220165121), Beta (111.0b3/20230219190218) and Release (110.0/20230214051806) under Windows 10 x64 and macOS 11.3.1.
Could you confirm that the workaround proposed in bug 1771328, will fix the issue until this bug is resolved?
Creating the menu at the top level of the background script works until the browser receives an update. After which, the extension needs to be disabled and re-enabled.
Updated•2 years ago
|
Comment 8•2 years ago
|
||
The original title of this bug described it as "MV3" related. Title is "neutral" now, but since I don't see it explicitly mentioned, I just want to point out this seems to be a bug affecting MV2-extensions too.
Also a user of one of my (MV2-)extensions says that if you delete file webext.sc.lz4 in Firefox profile (C:\Users\xxx\AppData\Local\Mozilla\Firefox\Profiles\xxx.default\startupCache\webext.sc.lz4) it will remove the menu-item my extension has created. Apparently this is something that CCleaner might do, and according to user, the disappearing menu-item is "my fault", not a problem with CCleaner. I'm not sure about that, should menu-items be robust to deletion of webext.sc.lz4? Is there maybe a connection to this issue?
Comment 10•1 year ago
|
||
The underlying issue (runtime.onInstalled not firing) already has a more specific bug, at bug 1700797. I'll move the WECG tracking over to that one to decouple it from the menu issue.
In comment 2, I added a test case that allegedly works in Chrome. Despite runtime.onInstalled not firing, the test case worked because the menu registration persisted.
Comment 11•1 year ago
|
||
This bug will be resolved when bug 1771328 or bug 1700797 (or both) are fixed.
Description
•