# MV3 keep data in memory when popup closes

**URL:** <https://discourse.mozilla.org/t/mv3-keep-data-in-memory-when-popup-closes/110931>\
**Category:** Development\
**Tags:** manifest-v3\
**Created:** [February 11, 2023, 12:28am UTC](https://discourse.mozilla.org/t/mv3-keep-data-in-memory-when-popup-closes/110931 "2023-02-11T00:28:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![muwave](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@muwave](https://discourse.mozilla.org/u/muwave)\
**Post date:** [February 11, 2023, 12:28am UTC](https://discourse.mozilla.org/t/mv3-keep-data-in-memory-when-popup-closes/110931/1 "2023-02-11T00:28:49Z")

</div>

Each time I open my MV3 extension the javascript runs from the beginning, it’s not persistent. If I set some variable and then close the extension, when I open it again the value stored in the variable is gone.  
I’m trying to keep a few variables in memory. I believe I can do something similar with `chrome.store.session`, but that’s not available on Firefox, so what can I do?  
Also keep in mind that the data I’m trying to get to be persistent could be sensitive, so I can’t just save it in local storage. It should be in memory while the browser is open and then get wiped.

To load the script from the manifest I’m using

```auto
"background": {
    "page": "background.html"
  }

```

where `background.html` is a page that just loads the script. I’m doing it like this because it’s the only way I was able to get the script to load as a module.

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [February 11, 2023, 8:57am UTC](https://discourse.mozilla.org/t/mv3-keep-data-in-memory-when-popup-closes/110931/2 "2023-02-11T08:57:40Z")

</div>

I don’t think you can right now. Session storage is not yet implemented in Firefox:

> **[1687778 - MV3 in-memory storage API (storage.session)](https://bugzilla.mozilla.org/show_bug.cgi?id=1687778)**
>
> NEW (nobody) in WebExtensions - Storage. Last updated 2023-02-10.

You may need to downgrade to MV2 for now.

Or maybe use some crazy workaround, for example Alarms API is not persistent in Firefox (all alarms are removed after restarting Firefox). So you could create dummy alarm and encode the “session data” as string into alarm name 😃 (using `JSON.stringify` you can encode whole objects and who knows if there is an alarm name length limit, probably not 🙂 ).

EDIT: now I remember discussion about making alarms persistent in MV3 (as it should be) so now I’m not sure if it’s fixed yet or not

---

<div class="post-metadata">

**Author:** ![muwave](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@muwave](https://discourse.mozilla.org/u/muwave)\
**Post date:** [February 11, 2023, 10:56am UTC](https://discourse.mozilla.org/t/mv3-keep-data-in-memory-when-popup-closes/110931/3 "2023-02-11T10:56:54Z")

</div>

That’s disappointing… do you have an idea of how long it will take for them to implement it?

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [February 11, 2023, 11:19am UTC](https://discourse.mozilla.org/t/mv3-keep-data-in-memory-when-popup-closes/110931/4 "2023-02-11T11:19:20Z")

</div>

Well, I can’t tell for sure. But currently the bug has dependency to:

> **[1573659 - (manifest-v3-background-service-worker) \[meta\] Background Service...](https://bugzilla.mozilla.org/show_bug.cgi?id=1573659)**
>
> NEW (nobody) in WebExtensions - General. Last updated 2023-01-18.

which is a huge thing that’s gonna take a long time to implement.

So I would say we will be lucky to get it by the end of September when the new Firefox ESR 115 is released.
