LocalStorage icon indicating copy to clipboard operation
LocalStorage copied to clipboard

[Feature Request] If local storage is unavailable, provide an in-memory alternative

Open csharpfritz opened this issue 3 years ago • 7 comments
trafficstars

Is your feature request related to a problem? Please describe. If a user has disabled cookies in their browser, all local storage access throws an error.

Describe the solution you'd like Can we provide an alternate in-memory storage provider instead of using the browser localStorage so that code will still work, but not persist between sessions.

csharpfritz avatar Aug 27 '22 15:08 csharpfritz

Hey @csharpfritz!

Thanks for raising this issue. I didn't realise local storage was disabled along with cookies--you learn something new everyday!

Yes, I think swapping to an in-memory option would be possible. It's what we do for the test extensions already.

I think this should be a setting developers turn on, rather than being a default. Some new API like, EnableInMemoryStorageFallback. We can then use the result of the navigator.cookieEnabled JavaScript API to enable the in-memory provider.

chrissainty avatar Aug 27 '22 22:08 chrissainty

I like the idea of a configuration option, but I think if localStorage isn’t available, developers should have an appropriate exception thrown

Jeff

On Aug 27, 2022, at 18:43, Chris Sainty @.***> wrote:

 Hey @csharpfritz!

Thanks for raising this issue. I didn't realise local storage was disabled along with cookies--you learn something new everyday!

Yes, I think swapping to an in-memory option would be possible. It's what we do for the test extensions already.

I think this should be a setting developers turn on, rather than being a default. Some new API like, 'EnableInMemoryStorageFallback'. We can then use the result of the 'navigator.cookieEnabled' JavaScript API to enable the in-memory provider.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

csharpfritz avatar Aug 27 '22 22:08 csharpfritz

Interesting, what use would the exception have for developers? The issue will only surface when the application is running on end users devices. Throwing an exception at that point would potentially kill the application, depending on how the developer has designed their code.

Wouldn't this be a feature a developer would enable ahead of time in order to keep things running if the end user has disabled cookies?

EDIT: Just realised, do you mean throw an exception if the developer hasn't enabled the new in-memory feature? So thing don't fail silently.

chrissainty avatar Aug 28 '22 16:08 chrissainty

I'm referring to an exception if AppSettings is inaccessible and the In-Memory fallback is not enabled.

"AppSettingsUnavailableException" or similar

csharpfritz avatar Aug 29 '22 15:08 csharpfritz

Hi,

This would be a great addition! Am I correct to assume that data in the InMemory fallback only exists untill the user reloads the app?

joepvtl avatar Sep 08 '22 10:09 joepvtl

Yes, in a WebAssembly scenario all context is lost when the app is reloaded.

For users who are privacy concerned, this should be a fair consideration in exchange for not writing any content to the local disk.

On Sep 8, 2022, at 06:19, joepvtl @.***> wrote:

 Hi,

This would be a great addition! Am I correct to assume that data in the InMemory fallback only exists untill the user reloads the app?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

csharpfritz avatar Sep 08 '22 12:09 csharpfritz

Sorry this has taken so long to make any progress. I've added in a new BrowserStorageDisabledException that will through if the browsers storage is unavailable.

For now, I've decided not to implement a fall back though. This is due to the fact it will behave differently to how local storage, i.e. not persistent and I'd like to get a bit more feedback on this before I add it to the library.

The work for the exception has been separated out into #192 to keep things tidy. This issue can remain for the potential fallback option.

chrissainty avatar Nov 09 '22 07:11 chrissainty