Manifest V3 migration guide | Firefox Extension Workshop says that you need to “Ensure listeners are at the top-level and use the synchronous pattern.”
There seem to be two exceptions:
- runtime.onUserScriptConnect
- runtime.onUserScriptMessage
You can:
- Request the “userScripts” permission
- Register your userscript(s)
- Add the above listeners
- If you then terminate the background script, and a userscript then sends a message to the background script, it wakes up, even though the listeners were added asynchronously.
(Otherwise, the extension would need to reload itself after step 2.)
Questions:
- Are onUserScriptConnect / onUserScriptMessage the only listeners you can register asynchronously?
- The documentation for onUserScriptConnect / onUserScriptMessage says:
”In Firefox, this event requires the userScripts permission. In Chrome, the event is always present, including in extensions that don’t declare the userScripts permission.”
Why are these events not always present in FF? I would guess for security reasons. But how would that be a problem?