Closed Bug 1795801 Opened 2 years ago Closed 1 year ago

Only the first listener is persisted; multiple listeners not triggered when event page awakes

Categories

(WebExtensions :: General, defect, P2)

defect

Tracking

(firefox113 fixed)

RESOLVED FIXED
113 Branch
Tracking Status
firefox113 --- fixed

People

(Reporter: robwu, Assigned: rpl)

References

(Blocks 2 open bugs)

Details

(Keywords: dev-doc-complete, Whiteboard: [addons-jira])

Attachments

(3 files)

When an extension registers multiple listeners for the same event, only the first event listener is called when the event page wakes up in response to the event being triggered.

STR:

  1. Visit about:config and set extensions.eventPages.enabled pref to true.
  2. Visit about:debugging and load the attached extension. It registers 4 listeners.
  3. Click "Terminate background" button to terminate the event page.
  4. Click the extension button twice.
  5. Inspect the background console.

Expected:

  • 1 2 3 4 - should have been logged after the first click.
  • 1 2 3 4 - should have been logged after the second click.

Actual:

  • 1 - logged after the first click
  • 1 2 3 4 - logged after the second click.

This happens because we key persistent listeners by the API path: https://searchfox.org/mozilla-central/rev/0a2eba79c24300ce0539f91c1bebac2e75264e58/toolkit/components/extensions/ExtensionCommon.jsm#2548,2550-2553
Consequently, later registrations are missed.

When this bug is fixed, make sure to also add test coverage for the scenario of removing a listener and/or re-adding a listener.

We might be able to address this by modifying what "keys" is.

https://searchfox.org/mozilla-central/rev/0a2eba79c24300ce0539f91c1bebac2e75264e58/toolkit/components/extensions/ExtensionCommon.jsm#2548

keys = [persistentId++, uneval(args)]

Along with touchups in other places where we access keys.

In the short term, we could document that only the first listener of a type is persisted.

Severity: -- → S2
Priority: -- → P2
Whiteboard: [addons-jira]
Duplicate of this bug: 1797949
Assignee: nobody → lgreco
Status: NEW → ASSIGNED

Not actually related to the change that the bug is tracking, but I did notice this an unexpected error
that was spamming the logs while I was investigating failures from one of the event pages / persistent
listeners tests as part of the rework of the persistent listeners data written in the XPIStates JSONFile.

Depends on D171769

Pushed by luca.greco@alcacoop.it:
https://hg.mozilla.org/integration/autoland/rev/de0be12a7f42
Support persisting and priming more then one listener for the same event and arguments. r=robwu
https://hg.mozilla.org/integration/autoland/rev/7e975ec3f0a3
Avoid logspam due to xpcshell tests without any system addon set throwing from cleanupStatingDir. r=willdurand
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 113 Branch

Please mention this in the "Firefox 113 for developers" MDN article.

Keywords: dev-doc-needed

Release notes added in #25779

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

Attachment

General

Created:
Updated:
Size: