

Menus and Scripting APIs also support persistent data: Here’s more info on background script functions. Use this API anytime you need direct access to a background page that may be suspended or closed. For instance, you may need a background script to run a process while the user is involved with a browser action or side panel. Use `` if you need a background page to run processes unrelated to events.(Note that Firefox recognizes arguments passed to addListener and does not create multiple listeners for the same set of arguments.)

This works with nearly all events in the WebExtensions API. This way, if your background is sleeping Firefox knows to wake the script whenever a new tab is spawned. Event listeners must be added at the top level execution of your script. Use an event listener like `` in your background script.Now that your background script is non-persistent, you need to tell Firefox when to wake up the page if it’s suspended. Here’s more info on background scripts with implementation details. To turn your background into an Event Page, set `persistent: false` on the background page in your manifest.json.


Therefore, it’s an ideal time to consider migrating your Manifest V2 extensions. Early next year, Firefox will release Mozilla’s Manifest V3 (MV3).
