# How nonpersistent background pages work

**URL:** <https://discourse.mozilla.org/t/how-nonpersistent-background-pages-work/113359>\
**Category:** Development\
**Tags:** manifest-v3\
**Created:** [April 15, 2023, 2:39pm UTC](https://discourse.mozilla.org/t/how-nonpersistent-background-pages-work/113359 "2023-04-15T14:39:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![metastable](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/metastable/32/61647_2.png) [@metastable](https://discourse.mozilla.org/u/metastable)\
**Post date:** [April 15, 2023, 2:39pm UTC](https://discourse.mozilla.org/t/how-nonpersistent-background-pages-work/113359/1 "2023-04-15T14:39:16Z")

</div>

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

```javascript
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?

---

<div class="post-metadata">

**Author:** ![skeletonxf](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@skeletonxf](https://discourse.mozilla.org/u/skeletonxf)\
**Post date:** [April 15, 2023, 5:04pm UTC](https://discourse.mozilla.org/t/how-nonpersistent-background-pages-work/113359/2 "2023-04-15T17:04:35Z")

</div>

You may want to use [https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onInstalled](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.
