Make settings page opening compatible with service worker
Background / User story
Manifest v3 forces us to run our background scripts in a service worker, which can be suspended/terminated at any time. Therefore we have to make sure that we add all event listeners synchronously, or they may not be called when the service worker activates.
Potential breakage:
- Settings page opens in a new tab, despite it already being open in a different tab.
- Confirmation dialog isn't shown in settings page after clicking on a subscribe link.
- "Show useful notifications" option in settings page isn't highlighted when clicking on "Configure notification settings" button in notification.
What to change
- Design: N/A
- Research: N/A
- Spec: N/A
- Legal: N/A
-
Development: Adjust code to add all event listeners synchronously:
-
browser.*.addListener()
- lib/pages/options:
showOptions()
determine whether settings page has loadedruntime.onConnect
tabs.onRemoved
tabs.onUpdated
- lib/pages/options:
-
Hints for testers
- See list of potential breakage under "Background".
- Settings page opens/focuses when clicking on the gear icon in the icon popup.
- When opening the settings page with an event (e.g. subscribe link, notification configuration link) it should work regardless of whether the settings page was already open or not.
- Focusing a section in the settings page (e.g. notification configuration link) should still work after closing the settings page and opening it again.
- Settings page shouldn't open more than once.
- The extension is only keeping track of the settings page that it last opened itself. So if the settings page was manually opened multiple times (e.g. by copy-pasting its URL into a new tab), the behavior is not defined and is expected to lead to odd behavior (e.g. the subscribe link dialog may be displayed in one of the tabs but the other one receives focus).
- Enable toggle should be shown in mobile settings page when opening it via the respective browser menu item.
Hints for translators
N/A
Further information
See also ui#1070 for information on which code is run on service worker activation.
Edited by Thomas Greiner