Overview
api.storage wraps localStorage with automatic JSON serialization.
Global Storage Methods
storage.get(key)
Retrieve a value. Returns null if not found.
Returns:
any | null
storage.set(key, value)
Store a value (auto-serialized to JSON).
storage.set() emits a storage:change event automatically, so other plugins can react to storage updates.storage.remove(key)
Delete a stored key.
storage.list()
Returns an array of all localStorage keys.
string[]
storage.clear()
Clears all localStorage data. Use with caution.
Plugin-Scoped Storage
These methods automatically prefix keys withplugin:{pluginId}:, preventing collisions between plugins. The current plugin ID is determined automatically.
storage.getForPlugin(pluginId, key)
Retrieve a value scoped to a specific plugin.
Returns:
any | null
storage.setForPlugin(pluginId, key, value)
Store a value scoped to a specific plugin.
setForPlugin() emits a storage:change event with the pluginId field set, so listeners can identify which plugin changed.Best Practices
Use plugin-scoped storage
Use plugin-scoped storage
Prefer
getForPlugin/setForPlugin over manual prefixing — it’s safer and cleaner:Use nullish coalescing for defaults
Use nullish coalescing for defaults
See Also
- Storage concept — detailed guide with examples
- Persisting Data guide — real-world patterns