'What is the proper way to store and read data in a chrome extension
I have an extension that uses(used) localStorage a lot for checking whether a user was logged in (ie: if (localStorage.getItem("username")) {..User logged in. Do stuff}.
I am updating the extension to use Manifest v3 and am trying to switch to chrome.storage.local and it is causing some grief as it's no longer a simple fact to check the localStorage item and then do stuff due to the asynchronicity (Is that a word?) of chrome.storage.
With that, I know I am going to make some pretty significant changes so I wanted to get some feedback on how other people would handle this.
As mentioned, once a user is logged in successfully, their username is saved in localStorage and we check that before running most functions. I am thinking that we could use a "loggedIn" status variable in chrome.storage at login and then have something in the onChange on logout for chrome.storage to reset that but what would be the best way to keep track of a "loggedIn" status variable. This would need to be accessed by the service_worker and the content pages. This also should be persistent and the data should be available even if the browser is closed and re-opened.
I have a couple of ideas but would like to hear how other would approach this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
