Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
reduxed-chrome-storage
Advanced tools
Redux-compatible interface to chrome.storage. Unified way to use Redux in all modern browser extensions. The only way to get Redux working in Manifest V3 Chrome extensions
Redux interface to chrome.storage
. Unified way to use Redux in all modern browser extensions. The only way to get Redux working in Manifest V3 Chrome extensions (aside from full reproduction of the Redux code).
npm install reduxed-chrome-storage
import { createStore } from 'redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducer from './reducer';
const options = {
createStore: createStore,
namespace?: ...,
chromeNs?: ...,
browserNs?: ...,
storageArea?: ...,
storageKey?: ...,
bufferLife?: ...
};
const asyncStoreCreator = storeCreatorFactory(options);
asyncStoreCreator(reducer).then(store => {
const state = store.getState();
...
});
async/await
):...
async () => {
const asyncStoreCreator = storeCreatorFactory({ createStore });
const store = await asyncStoreCreator(reducer);
...
}
...
...
async () => {
const store = await storeCreatorFactory({ createStore })( reducer );
...
}
...
import { createStore } from 'redux';
import storeCreatorFactory from 'reduxed-chrome-storage';
import reducer from './reducer';
const changeListener = (store, oldState) => {
const currentState = store.getState();
...
};
const options = {
createStore: createStore,
changeListener: changeListener,
namespace?: ...,
chromeNs?: ...,
browserNs?: ...,
storageArea?: ...,
storageKey?: ...,
bufferLife?: ...
};
storeCreatorFactory(options)(reducer);
Type: function
The original Redux's createStore
function. The only mandatory option.
Type: string
Default: 'chrome'
A string to identify the APIs namespace to be used, either 'chrome'
or 'browser'
. If this and the next two options are missing, the chrome namespace is used by default.
Type: host object
(ChromeNamespace
in Typescript definition)
The chrome namespace within Manifest V2 extension. If this option is supplied, the previous one is ignored.
Type: host object
(BrowserNamespace
in Typescript definition)
The browser namespace within Firefox extension, or the chrome namespace within Manifest V3 chrome extension. You may pass the chrome namespace within Manifest V3 to make this library use Promise-based APIs under the hood. If this option is supplied, the previous two are ignored.
Type: function
(ChangeListener
in Typescript definition)
A function to be called whenever the state changes, receives two parameters:
This option only makes sense in Manifest V3 service workers or event-driven background scripts. However it works in the same way in persistent scripts too, which may be useful for cross-browser development. Note: if this option is supplied, the async store creator returned by the factory is not supposed to be immediately used for store creation; its only purpose in this case is to hold the arguments to be passed to the original createStore
upon a one-time store creation.
Type: function
(ErrorListener
in Typescript definition)
A function to be called whenever an error occurs during chrome.storage
update, receives two parameters:
Type: string
Default: 'local'
The name of chrome.storage
area to be used, either 'sync'
or 'local'
. Note: it is not recommended to use sync
area for immediately storing the state of extension. Use local
area instead - it has less strict limits than sync
. If you need to sync the state (entirely or partially) to a user's account, create a temporary store of sync
area, then copy the needed data to (or from) the main store (of local
area).
Type: string
Default: 'reduxed'
Key under which the state will be stored/tracked in chrome.storage
.
Type: number
Default: 100
Lifetime of the bulk actions buffer (in ms).
The usage is the same for any extension component (background or content script or popup - no matter).
asyncStoreCreator
function returned by storeCreatorFactory
is similar to the original Redux's createStore
function except that unlike the latter asyncStoreCreator
runs in async way returning a promise instead of a new store (which is due to asynchronous nature of chrome.storage
API). asyncStoreCreator
has the same syntax as its Redux's counterpart, though its 2nd parameter has a slightly different meaning. Unlike Redux, this library features state persistence through extension's activity periods (browser sessions in the case of persistent extension). With Reduxed Chrome Storage the current state is always persisted in chrome.storage
by default. So there is no need to specify a previosly (somewhere) serialized state upon store creation/instantiation. However there may be a need to reset some parts (properties) of the state (e.g. user session variables) to their initial values upon store instantiation. And this is how the 2nd parameter is supposed to be used in Reduxed Chrome Storage: as initial values for some specific state properties. To be more specific, when a new store is created by asyncStoreCreator
, first it tries to restore its last state from chrome.storage
, then the result is merged with the 2nd parameter (if supplied).
If you're developing a Manifest V3 Chrome extension or a Manifest V2 extension with non-persistent background script, you have to keep in mind that your background script must comply with requirements of event-based model. In the context of usage of this library it means that asyncStoreCreator
's promise callback should not contain any extension event listener (e.g. chrome.runtime.onStartup
etc). If async/await
syntax is used, there should not be any event listener after first await
occurrence. Furthermore, storeCreatorFactory
should not be called inside any event listener (as it implicitly sets up chrome.storage.onChanged
event listener).
Licensed under the MIT license.
FAQs
Redux interface to chrome.storage (browser.storage). A unified way to use Redux in all modern browser extensions. The only way to get Redux working in Manifest V3 Chrome extensions
The npm package reduxed-chrome-storage receives a total of 235 weekly downloads. As such, reduxed-chrome-storage popularity was classified as not popular.
We found that reduxed-chrome-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.