Jonathan
Jonathan

Reputation: 8901

How is chrome storage affected when an extension is updated?

If a user adds data to an extensions chrome.storage.local/sync the extension then gets updated because a new version is released. Will the chrome.storage.local/sync still be the same or will it reset?

Upvotes: 6

Views: 1540

Answers (2)

weiya ou
weiya ou

Reputation: 4336

If chrome.storage.sync.set is not called when the extension is updated, then the old data remains.

If the state key value changes during the update, the data needs to be cleared, otherwise a lot of discarded values will accumulate.

const initData = { a: 10, b: 20 };

// Use old value if there is one
// If a new value is added, the value of `initData` is used by default
chrome.storage.sync.get(dataRaw => { 
  const data = Object.entries(initData).reduce((acc, [k, v]) => {
    return { ...acc, [k]: dataRaw[k] === undefined ? v : dataRaw[k] };
  }, {});
 // Clean up unwanted data
  chrome.storage.sync.clear(() => chrome.storage.sync.set(data));
});

Upvotes: 0

Xan
Xan

Reputation: 77571

No, it will be the same.

It's actually quite common to have some "schema version" variable inside storage that you can use to upgrade the storage if your data format changes with an update.

However, it's important to remember that uninstalling an extension will completely wipe the storage, including the sync storage if Sync is enabled.

Upvotes: 10

Related Questions