🎛️ 2026-11-27 | Designing a Storage Control Panel

🧑💻 Author’s Note
👋 Issue #61 asks for a settings page that shows the browser storage Domination uses and lets players clear it piece by piece. It should discover what’s stored rather than rely on a hand-maintained list, so it doesn’t need updating every time the app saves something new.
This post is the design only. I’ll build it in the same pull request after you review it. It follows the storage investigation in Why Domination Runs Out of Browser Storage, whose first recommendation was to measure what a player’s browser actually holds. This panel is that measurement, done on the player’s own device.
The post covers what Domination stores today, what a web page can discover and delete, a recommended design in independent layers, a suggested delivery order, and a list of choices. The bold option in each row is my recommendation. All source links point to the revision I studied.
📌 Update: You approved the recommendation, and the panel shipped in Domination 0.46.0. Building the Storage Control Panel describes the implementation. A few details changed while building it, and the snippets below are updated to match:
StorageInspectoris a module of plain functions, not a type class.- The
Registrationlocator holds no browser handle. classify,inventoryandremovalPlantake a context of room, version and service-worker scope.- The generation advances both before and after removal.
- The storage fact is passed into the Debug report rather than read by it.
🧭 Context: What Domination Stores Today
Almost everything lives in localStorage. The storage adapter writes JSON strings under plain key names that are defined in Main or written directly as string literals ("kingdom", "bot_delay", …). Room state is prefixed by scopedKey as room/<code>/<name>; the global room uses the bare name.
| Keys | Scope | Held in memory by the page? | What clearing it means |
|---|---|---|---|
player-id | Device | Yes | A new identity is created on the next load; other players see a new name entry |
username | Device | Yes | A random “lurker” name on the next load |
kingdom, player_index, player_count, bot_strategies, bot_delay | Device (game setup) | Yes | Setup returns to its defaults |
server-url, mailbox-url | Device | Yes | Default relay and mailbox |
rename_proposals | Device | Yes | No proposals; Rename → Clear does the same but keeps the key with an empty map |
game_state | Per room | Yes | The room opens without a saved game; in a game room, the room’s mailbox or other players can send it back |
game_state_0 … game_state_9 | Per room | No (read only when you press Undo) | Undo can’t go back to the cleared steps |
chat | Per room | Yes | The room’s chat history is gone |
mailbox_sync, game_version | Per room | Yes | Sync bookkeeping is rebuilt; clearing mailbox_sync forgets that your latest move hasn’t reached the mailbox yet |
debug_log, sync_journal | Device (diagnostics) | Yes, in DebugLog.js buffers | No diagnostics; Debug → Clear log does the same but keeps the keys with empty lists |
seed | Device (legacy) | No | Nothing. Only the dormant Bugout transport reads or writes it, so it’s left over from older versions |
Outside localStorage, the service worker keeps one Cache Storage cache named after the app version, holding the app shell. Domination uses no sessionStorage, IndexedDB, origin private file system (OPFS) or cookies today.
Four facts from this inventory shape the design:
- 🧠 Most keys are held in memory too.
Initializereads most of them once at start, and the page writes its in-memory copy back on the next change.DebugLog.jspersists its buffers within a second of new log lines and again when the page is hidden, frozen or unloaded. Removing a key from storage alone doesn’t stop the running page from writing it back. - 🆕 Every missing key already has a first-visit default.
Initializefalls back to a default, or generates a new value, for every key it reads and can’t load. So a reload after clearing goes through code that runs every time someone opens the game for the first time. - 🌐 The origin may be shared. Storage belongs to an origin, not a path (MDN). The preview at
bagrounds.github.io/dominationshares its origin with every other GitHub Pages project of that account, andhttp://localhost:<port>with anything else served on that port. Domination’s key names aren’t namespaced (username,seed), so on a shared origin a key the app doesn’t recognize could belong to another app, and even a key it does recognize could have been written by one. On the production origin,domination.fun, nothing else is served. - 🏷️ Room keys already describe themselves. Every room key is
room/<code>/<name>, and room codes can’t contain/. So any key under a room prefix can be shown with its room, even if its<name>is new. Global-room keys have bare names, so they can only be recognized by name.
🔎 What a Page Can Discover and Delete
The panel’s discovery uses only standard APIs, each feature-detected, so a missing API or a blocked storage area is shown as “unavailable” instead of breaking the panel:
| Area | Discover | Size | Delete |
|---|---|---|---|
localStorage / sessionStorage | length and key(i) list every key | Exact length of key plus value in UTF-16 code units (not bytes) | removeItem(key) |
| IndexedDB | indexedDB.databases() lists names and versions (Baseline) | None per database | indexedDB.deleteDatabase(name); it fires blocked and waits while any connection, in any tab including this one, is open |
| Cache Storage | caches.keys(), then cache.keys() per cache | Sum of response body sizes; opaque responses report none | caches.delete(name) or cache.delete(request) |
| Service workers | navigator.serviceWorker.getRegistrations() | — | registration.unregister() |
| OPFS | navigator.storage.getDirectory(), then its entries | File sizes | removeEntry(name, { recursive: true }) |
| Cookies | document.cookie: only cookies that apply to this page’s path and aren’t HttpOnly, so not a full inventory | Characters | Not reliable from script without knowing each cookie’s path and domain, so listed only |
| Whole origin | navigator.storage.estimate() and persisted() | An estimate across storage types; what it includes varies by browser | — |
Three limits matter:
- 📏 Web Storage has a small, fixed quota. About 5 MiB of
localStorageper origin (MDN); browsers count it slightly differently. The panel measures characters, the same unit the existing save errors report. It doesn’t turn them into an exact share of the quota; it labels any comparison as approximate. - 🧮
estimate()is notlocalStorageheadroom. It’s an estimate, sometimes rounded on purpose for privacy, and it doesn’t consistently include Web Storage. The panel shows it on its own line and never adds it to thelocalStoragetotal. - 🔔 Other tabs only learn by event, and events don’t stop writes. A
localStoragechange in one tab fires astorageevent in the origin’s other tabs, not in the one making the change. It’s a notification after the fact, so another tab can write before handling it. IndexedDB, caches and OPFS fire no such event.
Nothing in this table is Domination-specific, which is what makes the panel dynamic: if Domination moves game data to IndexedDB, as the earlier storage post suggested, its databases will show up without changes to the panel.
🏗️ Recommended Design
Five layers, each usable and testable alone. Layers 1–3 are pure; only 4 and 5 touch the browser.
1. 🔤 A key vocabulary: Domination.Data.StorageKey
The key names move out of Main into one closed type, so the code that saves a key and the panel that describes it share a single definition:
data RoomKey = CurrentGame | UndoStep Int | Chat | MailboxSync | GameVersion
data DeviceKey
= PlayerId | Username | Kingdom | PlayerIndex | PlayerCount
| BotStrategies | BotDelay | ServerUrl | MailboxUrl | RenameProposals
| ConsoleLog | SyncJournal | LegacyRelaySeed | ClearGeneration
data StorageKey = InRoom Room RoomKey | OnDevice DeviceKey
printKey :: StorageKey -> String -- the exact strings used today
parseKey :: String -> Maybe StorageKey
describe :: StorageKey -> { label :: String, consequence :: String } - 🔁
printKeyproduces today’s strings exactly (scopedKeystays the room-prefix rule), so no stored data needs migrating.ConsoleLogandSyncJournaltake their names fromDebugLog.jsthrough a foreign import, so the JavaScript stays the source of truth for its two keys. - 🧰
saveandloadcalls inMaintake aStorageKeyinstead of a raw string. Adding a key means adding a constructor, and the compiler then requires adescribecase. Writing a description is part of adding the key, not a separate panel update. - 🧯 Recognition is an enrichment, not a gate. A key that
parseKeydoesn’t know still appears in the panel with its size and a Delete button (see layer 2). - 🆕
ClearGenerationis the only new key: a small counter that keeps deleted data deleted (layer 5).
2. 🏷️ Classification: from raw entries to owners
Discovery returns raw entries without any Domination knowledge. Each entry carries a typed locator: exactly what its area needs to find and delete it again.
data WebStorage = Local | Session
data Locator
= WebStorageKey WebStorage String
| Database { name :: String, version :: Int }
| Cache String -- requests listed for visibility only
| Registration { scope :: String, script :: String } -- looked up again by scope to remove
| OriginFile String -- a top-level OPFS entry
| Cookie String -- listed only
type Entry = { locator :: Locator, size :: Maybe Int }
data Owner
= Known StorageKey -- parsed by StorageKey
| RoomData RoomCode String -- under room/<code>/ with an unknown name
| AppShell Freshness -- a cache or worker that looks like Domination's
| Unrecognized -- anything else on this origin
type Context = { room :: Room, version :: String, scope :: String }
classify :: Context -> Locator -> Owner RoomData is what keeps rooms dynamic: a new room key added with scopedKey is shown with its room before anyone gives it a description. A cache named vX.Y.Z is shown as app files, marked current when it matches the running Version and stale otherwise. Only Known is certain, and even that only on an origin that serves nothing else; the other owners are informed guesses, and layer 5 treats them that way.
3. 🧮 Inventory: one monoid, many views
Grouping is a foldMap from entries into a map of summaries:
data Group = ThisRoom | OtherRoom RoomCode | GlobalRoomGroup | Preferences
| Diagnostics | AppFiles | NotRecognized | OtherArea Area
newtype Summary = Summary { entries :: Int, size :: Int, unknownSizes :: Int }
-- Semigroup/Monoid by field-wise addition
type Section = { group :: Group, summary :: Summary, items :: Array Item }
inventory :: Context -> Array Entry -> Array Section - ➕
Summaryis a commutative monoid, so the panel’s totals and each group’s totals come from the same fold. Groups and entries are listed largest-first, so the thing filling storage is at the top. - 🧹 A removal is a pure plan as well:
removalPlan :: Context -> Array Item -> Selection -> Planturns “this key”, “this group” or “all Domination data” into the exact locators to delete, plus whether the clear generation has to advance (layer 5).
4. 🔌 Discovery and removal at the browser edge
One small FFI module, src/Capability/StorageInspector.js, in the style of the existing storage FFI: every call is wrapped in try/catch, every area is feature-detected, and each area reports either its entries or why it’s unavailable. Async APIs (IndexedDB, caches, OPFS, estimate) are wrapped with Effect.Aff.Compat, which is already a dependency, so no new dependencies are needed.
type AreaReport = { area :: Area, found :: Either String (Array Entry) }
type Discovery =
{ origin :: String
, areas :: Array AreaReport
, estimate :: Maybe { usage :: Number, quota :: Number, persisted :: Boolean }
}
discover :: Aff Discovery
remove :: Array Locator -> Aff (Array (Tuple Locator Removal))
data Removal = Removed | Waiting String | Failed String -- Waiting: e.g. a database still open The panel takes an inventory when its tab opens, after each removal, on Refresh, and on storage events. It never takes one on every render, because reading every localStorage value is synchronous. A database deletion that fires blocked is reported as Waiting (“close other tabs that use it”) rather than as a failure, because it finishes once the connections close.
5. 🖥️ The Storage tab
A new StorageTab joins the settings tabs, rendered by a new Domination.UI.Storage. Groups are native <details> elements, so expanding needs no extra state and works with assistive technology:
Storage [Refresh]
https://domination.fun · Kept until the browser needs space (not persistent)
Local storage: 1,284,113 characters in 47 keys (roughly a quarter of the usual 5 MiB)
Browser estimate: 3.1 MB used (all storage types)
▾ Room k7m2qp9x (this room) 612,401 · 14 keys [Clear room]
Current game game_state 41,233 [Show] [Copy] [Delete]
Undo step 3 game_state_3 41,002 [Show] [Copy] [Delete]
Chat chat 9,880 [Show] [Copy] [Delete]
▸ Room 3hx8vbn2 580,112 · 13 keys [Clear room]
▸ Global room 98,004 · 12 keys [Clear]
▸ Diagnostics 402,551 · 2 keys [Clear]
▸ Preferences 3,410 · 11 keys [Clear]
▸ Not recognized 812 · 3 keys
▸ App files: cache v0.45.1 (current), 5 files · 412 KB; 1 service worker [Reinstall]
Empty: session storage, IndexedDB, origin private files, cookies
[Clear all Domination data] - 🔒 The header line follows
persisted(): “Kept until the browser needs space” by default, or “Kept until you clear it” when the browser has granted persistent storage. The share of the usuallocalStoragelimit is labeled as rough, because browsers count differently. - ⚠️ Every delete is a two-tap confirmation in place: Delete becomes “Delete 14 keys (612,401 characters)? This is the room you’re in; the page will reload. Other players and the room mailbox keep their copy.” Confirm / Cancel. A group’s confirmation lists the keys it will delete. If the room still has a move the mailbox hasn’t confirmed, the confirmation says the move will be lost.
- 🛡️ A clear generation keeps deleted data deleted. Removing data that a page may hold in memory (any room’s keys or any preference) increments
ClearGenerationand reloads this page. Every page reads the counter when it starts. Before each write, the Storage capability’ssaveandDebugLog.jscompare it with the value they started with. If it changed, they don’t write:savereturns a newSaveErrorconstructor,Superseded, andMainreloads instead of showing the problem dialog.Mainalso reloads when astorageevent reports a new generation. So neither this tab’spagehidesave nor a move in another tab can write old data back, even before the other tab has handled the event. It costs one small read per save. The counter itself is never deleted, not even by Clear all Domination data; it only goes up. After the reload,Initializetakes its first-visit path for whatever is gone. - 🎯 Only what needs it reloads. Deleting undo steps, unrecognized keys, stale caches or databases doesn’t advance the generation. If the clearing tab doesn’t hold the deleted keys (another room’s, for example), it adopts the new generation instead of reloading. Other tabs can’t tell which keys went, so they reload; a reload restores everything that’s still saved.
- 🪵 Diagnostics cooperate instead of reloading.
DebugLog.jsgets aforget(key)that empties its buffer before the key is removed. It also listens forstorageevents that remove its keys, so other tabs drop their buffers too. Logging continues, so the key comes back right away with new lines, and the panel says so. - 🧭 Bulk clears only touch names Domination writes. Clear all Domination data removes
Knownentries only, so it never deletes unrecognized keys, a room key with an unknown name, or app files. Clear room also removes that room’sRoomDataentries, which its confirmation lists by name. Unrecognized entries can be deleted one at a time. On a shared origin, even a known name such asusernamecould have been written by another app, so the panel’s header shows the origin, and on any origin other thandomination.funthe bulk confirmation says other apps may share it. - 📦 App files are reinstalled, not deleted. The service worker fills its cache only when it installs, and every page load registers it again. Deleting the cache alone would leave the app without offline files until the next version. Unregistering alone would be undone on the next load. So app files get one action, Reinstall: unregister Domination’s worker, delete its caches, and reload, so the browser installs and fills them again. It’s disabled while the browser is offline, because the page couldn’t load without them. Stale caches and caches that aren’t Domination’s can be deleted one at a time.
- 🗂️ Show opens a read-only text area with the first 2,000 characters of a value; Copy copies the whole value with the existing
copyToClipboard. Values never go into bug reports. - 🐞 Bug reports gain one line. The report facts get a compact summary by category, with no key names or room codes, because old invite codes still grant access to their rooms. An example:
Storage: 1,284,113 chars in 47 keys; 6 rooms (largest 612,401); diagnostics 402,551; not recognized 812. It’s short enough to stay within the URL budget, and next time a report like issues #54 and #58 will show where the space went.
The existing Debug → Clear log and Rename → Clear buttons stay. They reset their data to empty rather than removing the keys, which is still right for those tabs.
6. 🧪 How it would be verified
- 🎲 Property tests (QuickCheck):
parseKey (printKey k) == Just kfor everyStorageKey, including arbitrary valid room codes and undo steps.printKeyis injective.- For every room code
cand namen,classifyputsscopedKey (GameRoom c) nin roomc, never in another room, including when one code is a prefix of another (abandabc). Bare names areKnownonly whenparseKeyrecognizes them; anything else staysUnrecognized. - The inventory’s total
Summaryequals the sum of its group summaries, and every entry is in exactly one group (a monoid homomorphism and a partition). - A room’s removal plan contains exactly the entries of that room. Clear all Domination data contains only
Knownentries. A plan advances the generation exactly when it contains a room or preference key, and the clearing tab reloads exactly when it also holds one of them. - The generation guard: for every sequence of saves and clears, no save after a clear writes with an older generation (a model test, like the existing Resync model tests).
- 🧩 Unit tests:
describetext for each key family; number formatting; the app-shell cache marked current or stale againstVersion. - 🌐 Browser run (the Playwright setup used for earlier features): seed preferences, two rooms, a foreign key, a
sessionStoragekey, an IndexedDB database and an extra cache. Open Settings → Storage. Check every item and size against what’s actually stored. Delete the other room and check that this room is intact and no reload happened. Clear this room and check that the reload shows game setup. Clear diagnostics and check that old lines don’t return afterpagehide. With two tabs in one room, clear the room in one and make a move in the other right away; check that the deleted game doesn’t come back. Reinstall app files and check that the cache is filled again and the app still loads offline afterwards.
7. 🚫 Out of scope
- 🗓️ Automatic retention (for example, forgetting rooms unused for 30 days). The panel makes old rooms visible and removable by hand; an automatic policy is a separate decision.
- 🗄️ Moving game data to IndexedDB, compression, and export/import, all discussed in the storage investigation. The panel will show IndexedDB once it’s used.
- 🏷️ Renaming keys under a
domination/prefix. It would make ownership certain on shared origins, but it needs a migration. For now, bulk clears are limited to known names and the origin is shown. A follow-up issue could add the prefix, andStorageKeywould make it a one-module change plus a migration. - 🧹 The service worker’s
activatestep deletes every cache not named after the current version, including other apps’ caches on a shared origin. Worth its own issue; the panel doesn’t change it.
8. 📦 Suggested delivery order
StorageKey,classify,inventory, andremovalPlanwith their property tests: pure code, no UI change.Mainswitches toStorageKey.- Discovery for Web Storage and the read-only Storage tab. Visibility alone helps players and bug reports.
- Removal with confirmations, the clear generation (including
Supersededand thestorageevent reload), andDebugLog.forget. - The other areas: Cache Storage, service worker and Reinstall, IndexedDB, OPFS, cookies,
estimateandpersisted. - The storage summary line in bug reports.
The implementation gets one minor version bump, as a new feature.
🗳️ Choices
1. Where the panel lives
- A — A new Settings → Storage tab (recommended).
- B — A section under Settings → Debug, next to the bug report.
2. Which storage areas are discovered
- A — Every area a page can see: Web Storage, IndexedDB, Cache Storage, service workers, OPFS, cookies, plus
estimateandpersisted(recommended). Empty areas collapse into one “Empty:” line. - B — Only what Domination uses today:
localStorage, Cache Storage and the service worker. Less code, but a future IndexedDB move needs a panel change, which the issue wants to avoid.
3. How keys are recognized
- A — A typed
StorageKeyshared bysave/loadand the panel (recommended): one definition, and the compiler requires a description for every new key. - B — A lookup table inside the panel only:
Mainunchanged and a smaller diff, but the table can drift from the code; drifted keys show up under Not recognized.
4. How entries are grouped
- A — By owner: this room, each other room, global room, preferences, diagnostics, app files, not recognized, then other areas; largest first (recommended).
- B — One flat list of every key, sorted by size.
- C — By storage area only.
5. How much of each value is visible
- A — Size only.
- B — Size, plus Show (first 2,000 characters, read-only) and Copy (whole value) (recommended).
- C — B, plus decoding saved games to show their step and player count. It’s more informative for picking which room to delete, but it ties the panel to the saved-game format and costs a parse per room.
6. Clearing data the running page holds
- A — Reload right after removing it, and let
Initializeuse its first-visit defaults (recommended). - B — Reset the in-memory state in place without reloading: smoother, but every key needs its own reset path, and missing one brings the data back.
- C — Remove it, then show a “Reload to apply” banner. Without the generation guard (row 9A), the page may save the old value again before the player reloads.
7. Confirmation
- A — A two-tap confirmation for every delete, stating the count, size and consequence (recommended).
- B — Confirm only bulk clears and data the page holds.
- C — No confirmation.
8. Bulk actions
- A — Per-group “Clear” and “Clear all Domination data”. The all-data clear removes known names only; a room’s clear also removes that room’s other keys, which it lists (recommended).
- B — A, plus Clear everything on this site: all Web Storage, databases, caches, files and service workers, including other apps’ data on a shared origin.
- C — Per-key deletes only.
9. Other open tabs
- A — The clear generation: saves check a counter before writing, tabs reload when it changes, and the panel refreshes on
storageevents (recommended). Deleted data stays deleted, at the cost of one extra small read per save. - B —
storageevents only: other tabs refresh or reload when they hear about a removal. Events arrive after the fact, so a tab can still write old data back first. - C — Ignore other tabs.
10. Bug reports
- A — One compact storage summary line in the report facts: totals, room count, the largest room’s size, and other categories by size, with no key names or room codes (recommended).
- B — One line per group: more detail, but it uses more of the URL budget.
- C — No change to bug reports.
11. Persistent storage
- A — Show whether the browser has granted persistence, read-only (recommended).
- B — A, plus an Ask the browser to keep this data button calling
navigator.storage.persist(). Firefox may prompt; Chromium and Safari decide silently, and the result isn’t a guarantee. - C — Don’t show it.
12. App files
- A — One Reinstall action that unregisters the service worker, deletes Domination’s caches and reloads, available only while online; stale caches can be deleted on their own (recommended).
- B — List app files read-only, with no actions.
- C — Separate delete buttons for each cache and the worker, with warnings. It’s more flexible, but easy to leave the app without its offline files.
🧩 Suggested Decision
The recommended first version is 1A, 2A, 3A, 4A, 5B, 6A, 7A, 8A, 9A, 10A, 11A, 12A. It’s a Storage tab that discovers every storage area the browser exposes and groups what it finds by owner, largest first. It lets players inspect, copy and delete one key or a whole group, with a confirmation that states the consequence. The page reloads whenever it held the deleted data in memory, a clear generation stops any tab from writing deleted data back, and bulk clears only remove names Domination writes. The delivery order lets you stop after step 2 (visibility only) or step 3 (Web Storage control) and still have a complete feature.
💬 Reply with Your Picks
Reply “Use the recommendation” to approve as-is, or list one letter per row, for example “1B, 2A, 3B, 4A, 5A, 6A, 7B, 8A, 9B, 10C, 11B, 12B”. Strike rows or delivery steps you don’t want yet (for example, “stop after step 3”), and add requirements as needed. I’ll update this design to match before implementing it.
✍️ Signed
🤖 Built with care by GitHub Copilot Coding Agent
📅 November 27, 2026
🏠 For bagrounds.org