question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

should use storage.local over window.localStorage

See original GitHub issue

Problem

This template currently uses localStorage(1, 2).

MDN advises against using local storage because of persistence issues:

Although this API is similar to Window.localStorage it is recommended that you don’t use Window.localStorage in extension code. Firefox will clear data stored by extensions using the localStorage API in various scenarios where users clear their browsing history and data for privacy reasons, while data saved using the storage.local API will be correctly persisted in these scenarios.

Proposal

Use storage.local via webextension-polyfill.

FYI VueUse useStorage accepts a 3rd parameter to accept a StoreLike object, so perhaps a wrapper around storage.local could have been passed in. However, storage.local APIs return promises so it cannot.

Because of storage.local’s async nature, it might be best to create another composable function that returns an isLoaded state.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
antfucommented, Dec 1, 2021

I wasn’t sure if this belongs in VueUse

@privatenumber I guess we are missing a composable to support async storage. I imagine we could have useAsyncStorage in VueUse, and convert the storage interface from webextension-polyfill in this template.

0reactions
hankolsencommented, Jan 4, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Window.localStorage - Web APIs | MDN
The localStorage read-only property of the window interface allows you to access a Storage object for the Document's origin; the stored data ...
Read more >
Please Stop Using Local Storage - Randall Degges
To keep it short, here's the only situation in which you should use local storage: when you need to store some publicly available...
Read more >
localStorage in JavaScript: A complete guide - LogRocket Blog
Window.localStorage is a read-only property that returns a reference to the local storage object used to store data that is only accessible to ......
Read more >
LocalStorage, sessionStorage - The Modern JavaScript Tutorial
The localStorage is shared between all windows with the same origin, so if we set the data in one window, the change becomes...
Read more >
How to Use Local Storage with JavaScript - Section.io
You should only use local storage when storing insensitive information. This is because third-party individuals can easily access the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found