Search code examples
javascriptgoogle-chromegoogle-chrome-extension

How do I clear chrome.storage.sync for testing my extension?


I am making a little logic game as a chrome extension, to add a high score I wanted to use chrome.storage.sync. I want to only create a variable if it doesn't exist (the first time someone is opening the extension). To test if what I wrote works I have to clear all data for myself, how could I do that? (the documentation speaks senior developer and I am not one of those so I don't understand)

https://developer.chrome.com/docs/extensions/reference/storage/


Solution

  • chrome.storage.local.clear()
    

    thats will Removes all items from storage.

    you can also remove some keys and not all items by,

    chrome.storage.local.get((data) => {
      // here you get all data and you can decide which keys to delete, 
      // in this case im deleting all keys explicitly
    
      chrome.storage.local.remove(Object.keys(data), resolve)
    })