Closed Bug 1851873 Opened 2 years ago Closed 2 years ago

Verify event page wakeup with runtime.onMessage/onConnect/onMessageExternal/onConnectExternal listener

Categories

(WebExtensions :: General, task, P1)

task

Tracking

(firefox120 fixed)

RESOLVED FIXED
120 Branch
Tracking Status
firefox120 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

An event page should wake up as soon as a top-level listener is triggered. This is especially important with runtime.onMessage, runtime.onConnect, runtime.onMessageExternal, runtime.onConnectExternal, because these are often called by an independent external trigger (in a content script or other extension). Because the caller (runtime.sendMessage / runtime.connect) are independent of the recipient, the likelihood of the event page being suspended is higher than usual.

These listeners are currently not persisted after an event page suspends, which means that runtime.connect / runtime.sendMessage will unexpectedly not wake up the event page.

The logic existed before, but was removed in https://hg.mozilla.org/mozilla-central/rev/7f4f1d605c69b3a471727810b6fc876187e8211e (bug 1624235). This made sense at the time because back then there was no support for non-persistent background pages. Now we need to restore the functionality (not necessarily with the same implementation).

Upon taking a closer look, the issue is not as bad as I thought.

While there is no explicit support for persistent listeners of the extension messaging APIs, the background is awakened as desired when a message is sent, due to https://searchfox.org/mozilla-central/rev/7fe1954b761abeff36122b4a6ac74619704ee787/toolkit/components/extensions/ExtensionParent.sys.mjs#332.

Because the call is unconditional, it doesn't require persistent listeners for the system to work. However, it also means that extension events are delayed (blocked on event page startup) even if the background does not have a listener. This is suboptimal but could be tackled later if desired.

For now, I'll resolve this ticket by adding unit tests that verify the behavior, and add some comments in the right locations.

Severity: S3 → N/A
Type: defect → task
Summary: Event page with runtime.onMessage/onConnect/onMessageExternal/onConnectExternal listener is not awakened → Verify event page wakeup with runtime.onMessage/onConnect/onMessageExternal/onConnectExternal listener
See Also: → 1852317
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/d9e7cc311757 Test coverage for event page wakup by extension messaging r=rpl
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 120 Branch
Regressions: 1856034
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: