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 or onStartup to only run something in response to the extension starting rather than resuming.

1 Like