[BUG] Data is not being stored in localStorage using Plasmo Storage
Opened this issue · 1 comments
thiagolmoraes commented
What happened?
Trying to use the Storage API in all ways but it doesn't work or no error message appears
import { Storage } from "@plasmohq/storage";
const storage = new Storage();
function Index() {
useEffect(() => {
const setAndGetData = async () => {
try {
await storage.set("key", "value");
const data = await storage.get("key"); // "value"
console.log(data);
} catch (error) {
console.log(error);
}
};
setAndGetData();
}, []);
Version
npm 8.19.4
node v16.20.2
Latest
What OS are you seeing the problem on?
Linux
What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
(OPTIONAL) Contribution
- I would like to fix this BUG via a PR
Code of Conduct
- I agree to follow this project's Code of Conduct
- I checked the current issues for duplicate problems.
sleekslush commented
@thiagolmoraes This is because the storage API will attempt to use chrome.storage
api where possible. The way you have it configured, the storage is going to write to chrome.storage.sync
. You can see this by querying await chrome.storage.sync.getAll()
from your code.
If you want to write to localStorage
in a content script, just write to localStorage
like you normally would.