!question I am getting chrome.storage undefined, how to enable it
!question I am getting chrome.storage undefined, how to enable it
chrome.storage as undefined, it means that you have not requested the storage permission in your extension's manifest file. To enable it, you need to add the following line to your manifest.json file:"permissions" field is an array of strings that lists all the permissions that your extension requires. In this case, we are requesting the storage permission.chrome.storage API in your extension without any issues.storage permission explicitly. Plasmo's Storage class abstracts the chrome.storage API and falls back to localStorage when the extension storage API is unavailable. This allows for state sync between extension pages, content scripts, background service workers, and web pages.package.json file. "storage" permission to the "permissions" array in your package.json file. Here's an example:"storage" permission to the "permissions" array. This will allow your extension to use the storage API provided by Plasmo."storage" permission to your package.json file, you can use the @plasmohq/storage library to interact with the storage API. This library abstracts the persistent storage API available to browser extensions and falls back to localStorage when the extension storage API is unavailable.@plasmohq/storage library to store and retrieve data:useStorage hook from the @plasmohq/storage library to store and retrieve data. The useStorage hook takes two arguments: the key to use for storing the data, and the default value to use if there is no existing value for the key.@plasmohq/storage library and adding the "storage" permission to your package.json file, you can easily store and retrieve data in your Plasmo-based browser extension.pnpm create plasmo?/Users/brendanbuono/src/plasmo/cli/create-plasmopnpm unlink -g create-plasmopnpm create plasmo <- it uses the remote version of plasmoexamples directory"permissions""permissions""permissions"Storage"storage""storage""storage""storage"@plasmohq/storage@plasmohq/storage@plasmohq/storage@plasmohq/storageuseStorageuseStoragenpm install @plasmo/configpnpm create plasmopnpm create plasmo/Users/brendanbuono/src/plasmo/cli/create-plasmopnpm unlink -g create-plasmo🔵 INFO | Installing dependencies...
Scope: all 22 workspace projects
/Users/brendanbuono/src/plasmo/cli/create-plasmo:
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND In ../../cli/create-plasmo: "@plasmo/config@workspace:*" is in the dependencies but no package named "@plasmo/config" is present in the workspaceexamples{
"name": "My Extension",
"version": "1.0",
"manifest_version": 2,
"permissions": [
"storage"
],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}{
"name": "my-extension",
"version": "1.0.0",
"description": "My awesome extension",
"permissions": [
"storage"
],
"devDependencies": {
"@plasmohq/plasmo": "^1.0.0"
}
}import { useStorage } from '@plasmohq/storage';
const MyComponent = () => {
const [value, setValue] = useStorage('my-key', 'default-value');
const handleClick = () => {
setValue('new-value');
};
return (
<div>
<p>Current value: {value}</p>
<button onClick={handleClick}>Update value</button>
</div>
);
};