# Disable auto delete of local storage

**URL:** <https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927>\
**Category:** web dev\
**Created:** [February 13, 2024, 6:37pm UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927 "2024-02-13T18:37:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wayne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wayne/32/16501_2.png) [@Wayne](https://forum.kirupa.com/u/Wayne)\
**Post date:** [February 13, 2024, 6:37pm UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/1 "2024-02-13T18:37:29Z")

</div>

I like to create PWAs with local storage.

I don’t want the browser to auto delete the local storage.  
Even indexedDB gets deleted after seven days of inactivity!

I wished PWA got the same treatment as local apps on a mobile device!

Any tips?

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 14, 2024, 4:38am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/2 "2024-02-14T04:38:17Z")

</div>

Hi Wayne! Store the data in the cloud AND local storage. If the local storage gets cleared, fetch the latest copy from the cloud. Would that work?

Cheers,  
Kirupa :unibrow:

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [February 14, 2024, 7:18am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/3 "2024-02-14T07:18:28Z")

</div>

Hey mate,

From what I can tell there is some form of persistence with this this API.

> **[StorageManager: persist() method - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/persist)**
>
> The persist() method of the StorageManager interface requests permission to use persistent storage, and returns a Promise that resolves to true if permission is granted and bucket mode is persistent, and false otherwise. The browser may or may not...

I’m not 100% on this because I use the file system for my personal apps and don’t really care about persisting data on web pages with SW’s.

Here’s my little snippet for a basic File System API (works in chrome and edge).

Have a play with that and get a feel for it… 🙂

```auto
export
    class FS {
    static #currentFolder
    static #currentFile

    static async openFolder() {
        try { FS.currentFolder = await window.showDirectoryPicker({ mode: "readwrite", startIn: "desktop" }) }
        catch (err) { return "cancelled" }

    }

    static async openFile(fileName) {
        if (FS.#currentFolder == null) await FS.openFolder()
        try {
            let fileHandle = await FS.#currentFolder.getFileHandle(fileName)
            let blob = await fileHandle.getFile()
            let text = await blob.text()
            return text
        }
        catch { return "not found" }
    }

    static async createFile(newName) {
        if (FS.#currentFolder == null) await FS.openFolder()
        try {
            for await (const [name, handle] of FS.#currentFolder.entries()) {

                if (name == newName) { return alert('file name in use') }
            }
            let newFile = await FS.#currentFolder.getFileHandle(newName, { create: true });
            return newFile
        }
        catch { return "failed" }
    }

    static async saveFile(fileName, data) {
        let fileHandle;
        try {
            for await (const [name, handle] of FS.#currentFolder.entries()) { if (name == fileName) { fileHandle = handle; break } }
            if (!fileHandle) return
            let writableStream = await fileHandle.createWritable();
            await writableStream.write(data);
            await writableStream.close();
        }
        catch { "failed" }
    }

    static async deleteFile(fileName) {
        try { await FS.#currentFolder.removeEntry(fileName) }
        catch { "failed" }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Wayne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wayne/32/16501_2.png) [@Wayne](https://forum.kirupa.com/u/Wayne)\
**Post date:** [February 14, 2024, 8:58am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/4 "2024-02-14T08:58:21Z")

</div>

I can’t store to the cloud because I want to avoid gdpr rules 😅

I can’t find what StorageManager is. Is it storing files on device?

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [February 14, 2024, 11:53am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/6 "2024-02-14T11:53:04Z")

</div>

From what I can tell `navigator.storage` returns a read only object called `StorageManager`

This Object allows you to:

- `estimate()` : “query” how much data your origin has been allowed on the device for `localStorage, caches, indexedDB sessionStorage` ect

- `persist()` : request permission to persist data from your origin

- persisted(): boolean if your origins data is persisted

- `getDirectory()` : access the file system directory for various operations

The code below should persist your data unless the user clears their history/ storage ect

```auto
if (navigator.storage && navigator.storage.persist) {
  navigator.storage.persist().then((persistent) => {
    if (persistent) {
      console.log("Storage will not be cleared except by explicit user action");
    } else {
      console.log("Storage may be cleared by the UA under storage pressure.");
    }
  });
}

```

TBH I haven’t tested it because I just use the file system…

---

<div class="post-metadata">

**Author:** ![Wayne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wayne/32/16501_2.png) [@Wayne](https://forum.kirupa.com/u/Wayne)\
**Post date:** [February 14, 2024, 11:59am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/7 "2024-02-14T11:59:05Z")

</div>

Thank you! I will give it a try

---

<div class="post-metadata">

**Author:** ![Wayne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wayne/32/16501_2.png) [@Wayne](https://forum.kirupa.com/u/Wayne)\
**Post date:** [February 14, 2024, 2:08pm UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/9 "2024-02-14T14:08:30Z")

</div>

It’s very sad how pwa never take off as I wanted. I have to write a native app to be able to store simple data for offline or use the cloud which violates GDPR

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 14, 2024, 5:33pm UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/10 "2024-02-14T17:33:00Z")

</div>

With Apple backtracking a bit with PWAs in the EU, the PWA shine continues to wear off.

---

<div class="post-metadata">

**Author:** ![Wayne](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/wayne/32/16501_2.png) [@Wayne](https://forum.kirupa.com/u/Wayne)\
**Post date:** [February 14, 2024, 5:49pm UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/11 "2024-02-14T17:49:07Z")

</div>

Can you by any chance speed me up to join project idx? I’m on a waiting list 🙏

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [February 14, 2024, 8:47pm UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/12 "2024-02-14T20:47:43Z")

</div>

PM me the email address you used to sign-up and I’ll see what I can do.

---

<div class="post-metadata">

**Author:** ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)\
**Post date:** [February 17, 2024, 9:17am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/13 "2024-02-17T09:17:12Z")

</div>

There might be another option to use a PWA with IOS file sytem.

This guy built a doodle app and published to APP store with a single html file using capacitor JS…

[![](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/4/d/4d68faf74bff46423781acaa19b07a379ebd20eb.jpeg "I built an entire app with NO FRAMEWORKS for Web, iOS, and Android") ](https://www.youtube.com/watch?v=Y382mhVOoR8&t=61s)

Capacitor also has a file system API…

> **[Filesystem Capacitor Plugin API | Capacitor Documentation](https://capacitorjs.com/docs/apis/filesystem)**
>
> The Filesystem API provides a NodeJS-like API for working with files on the device.

---

<div class="post-metadata">

**Author:** ![lukeharper](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lukeharper](https://forum.kirupa.com/u/lukeharper)\
**Post date:** [October 23, 2024, 9:50am UTC](https://forum.kirupa.com/t/disable-auto-delete-of-local-storage/664927/14 "2024-10-23T09:50:01Z")

</div>

Hello wayne ,  
PWAs can’t fully prevent browsers from deleting local storage or IndexedDB after inactivity. To improve persistence, use service workers, request user permission for persistent storage (`navigator.storage.persist()`), and regularly engage users to reset inactivity timers. However, PWAs still don’t get the same treatment as native apps.
