Skip to main content

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.
Returns: string[]

storage.clear()

Clears all localStorage data. Use with caution.
storage.clear() removes everything, including other plugins’ data and the plugin registry.

Plugin-Scoped Storage

These methods automatically prefix keys with plugin:{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

Prefer getForPlugin/setForPlugin over manual prefixing — it’s safer and cleaner:

See Also