Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Data is not being stored in localStorage using Plasmo Storage #1066

Open
2 of 3 tasks
thiagolmoraes opened this issue Sep 10, 2024 · 1 comment
Open
2 of 3 tasks
Labels
bug Something isn't working

Comments

@thiagolmoraes
Copy link

thiagolmoraes commented Sep 10, 2024

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.
@thiagolmoraes thiagolmoraes added the bug Something isn't working label Sep 10, 2024
@sleekslush
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants