This sounds like a potential bug, have you already reported it to us on bugzilla?
if you could provide us a small test extension that can trigger consistently the issue as you observed it, we could use it as a base for a reduced test case and investigate what makes that use case to don’t work as expected.
Technically what happens internally is that the new event listeners registered on each wake are going to replace “placeholder listeners” that are registered by the WebExtensions internals while the event page isn’t running.
These “placeholder listeners” (technically they are called “persisted listener” internally) are:
- registered based on the metadata of the listeners registered synchronously when the background page was previously executed.
- are responsible for waking up the event page when the event is being emitted
- once the event page has been woken up and it is running again, these placeholder listener may either:
- be replaced by real event listeners registered again by the background script, in which case all the events queued in the meantime will be forwarded to them
- be dropped if real event listeners are not be re-registered again by the background script, in which case all the events queued gets dropped because there wouldn’t be any event listener to handle them anymore
As juraj.masiar already mentioned, browser.storage.session
will be implemented also in Firefox and at that point it will be definitely one of the APIs that an extension could use to store some session-related data.
In the meantime, at least for some of the possible use cases:
-
browser.storage.local
may be an alternative WebExtensions API that is already available across all browsers vendors and manifest versions (but unlike browser.storage.session
, the data is also stored on disk and available across browser restarts)
-
if the background script is running as an event page and there is a need to store a small amount of data and have it accessible synchronously, localStorage
/sessionStorage
WebAPI may be another alternative available (but these DOM WebAPI are not going to be available in a service worker global and so they are not an option in a manifest_version 3 extension running on Google Chrome).