Open Bug 1817287 Opened 2 years ago Updated 1 year ago

browser.runtime.onInstalled event not fired when disabled add-on is re-enabled, and menus.create registration disappeared

Categories

(WebExtensions :: Frontend, defect, P2)

Firefox 110
defect

Tracking

(firefox110 affected, firefox111 affected, firefox112 affected)

Tracking Status
firefox110 --- affected
firefox111 --- affected
firefox112 --- affected

People

(Reporter: mb, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

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.

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 !

Flags: needinfo?(mb)

Confirmed.

STR:

  1. Load attached extension at about:debugging (or: rename .zip to .xpi, set xpinstall.signatures.required to false (Nightly only - not release!) and open the xpi from the location bar to install it)
  2. Right-click anywhere to see the new "Menus created at onInstalled" menu item
  3. Visit about:addons and disable then re-enable the add-on,
  4. 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
Flags: needinfo?(mb)

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

Status: UNCONFIRMED → NEW
Ever confirmed: true

There are two ways to fix this:

  1. Supporting onInstalled at enable as suggested in comment 3.
  2. Not removing the data (the approach from bug 1771328, which is similar to this bug - menus disappear when extension is reloaded).
Depends on: 1771328

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.

Severity: -- → S3
Priority: -- → P2
Summary: Strange MV3 behaviour - browser.runtime.onInstalled event and menus.create → browser.runtime.onInstalled event not fired when disabled add-on is re-enabled, and menus.create registration disappeared
Whiteboard: [wecg]

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?

Duplicate of this bug: 1829708

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.

Whiteboard: [wecg]

This bug will be resolved when bug 1771328 or bug 1700797 (or both) are fixed.

Depends on: 1700797
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: