How nonpersistent background pages work

Suppose I have the following code at the top level of a nonpersistent background script:

browser.tabs.query({}).then((tabs) => console.log(tabs));

Does this piece of code run every time the background script resumes?

If so, how can I make something run only once in the extension’s lifetime?

You may want to use https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onInstalled or onStartup to only run something in response to the extension starting rather than resuming.

1 Like