Skip to content

Parent issue: Local storage #4334

Open
0 of 3 issues completed
Open

Description

@ksen0

p5.js version

No response

What is your operating system?

No response

Web browser and version

No response

Actual Behavior

When sketches crash, work is lost.

Expected Behavior

The intended behavior is that local storage should be saving the sketch before each run. So if there's a crash, re-opening the tab should be fine. Work being lost may indicate a bigger problem with localStorage so we will being to investigate there.

Steps to reproduce

Details in child issues.

Activity

  1. added
    BugError or unexpected behaviors
    and removed on Oct 2, 2026
  2. ksen0 commented on Oct 2, 2026

    @ksen0
    MemberAuthor

    For research, may be worthwhile to consider "other standard APIs that might be more fit for purpose.
    See the MDN docs for File System API, and OPFS more specifically." thanks @SableRaf for the suggestion

  3. clairep94 commented on Oct 2, 2026

    @clairep94
    Collaborator

    @doradocodes should we close the children to de-dupe?

  4. SableRaf commented on Oct 3, 2026

    @SableRaf
    Contributor

    For research, may be worthwhile to consider "other standard APIs that might be more fit for purpose. See the MDN docs for File System API, and OPFS more specifically." thanks @SableRaf for the suggestion

    I did a bit more research so here are some clarifications.

    Note: The research below was done with some AI help. I verified the info with primary sources (mainly MDN, links below). However, this is all based on reading documentation, not experiments or first-hand experience, so take it with a grain of salt.

    IndexedDB

    IndexedDB is "a low-level API for client-side storage of significant amounts of structured data, including files/blobs", explicitely presented as an alternative to Web Storage API (localStorage and sessionStorage). It is "Widely available" according to MDN. This might be enough for our use case.

    Side note: IndexedDB is said to be somewhat awkward do work with. Libraries like Dexie claim to offer more convenient APIs for working with IndexedDB.

    OPFS

    OPFS (Origin Private File System) is "a storage endpoint provided as part of the File System API, which is private to the origin of the page and not visible to the user like the regular file system". It is a more recent standard than IndexedDB. Nevertheless, MDN lists OPFS as "Widely available."

    About persistence

    Both IndexedDB and OPFS use best-effort storage by default, so browsers may still evict the data if they need the storage. The Storage API provides navigator.storage.persist() can be used to request persistent storage. However, if the user clears site data, resets their browser profile, or looses access to the device, the data will still be lost.

    This is one place where the broader File System Access API could be useful: it can save a project to a user-selected file or directory on the actual local filesystem, so that copy is not tied to the browser's origin storage and can be treated like regular files (possibility of automated cloud backups, sending by email, file transfer services, etc). Browser support is more limited, though, so it would still need a fallback such as a convenient export/import mechanism for unauthenticated users. Note: an approach for sharing sketches as URLs is discussed in #4331 (comment) but it is limited to shorter sketches and does not replace the need for easier export/import.

    References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugError or unexpected behaviors

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions