nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.33k stars 3.89k forks source link

The limit of localStorage should be removed #7805

Open dreamsavior opened 2 years ago

dreamsavior commented 2 years ago

NWJS Version : 0.58.0 SDK Operating System : Win 10 64 bit

Expected behavior

As a desktop application we should have a full control of localStorage limit.

Actual behavior

The localStorage is limited just like chromium browser image

How to reproduce

Run this : window.open('https://arty.name/localstorage.html')

baconbrad commented 2 years ago

While I agree it should be when storing this much information you might want to use fs to directly use the users storage system. Depending on purpose fs will deliver much more flexibility and possibly speed.

We had a program that needed localStorage as it had to work in the browser as well. But it would exceed this limit. We found serializing JSON arrays into a string and compressing the string was a great solution. Look into lz-string or another alternative string compression algorithm. Keep in mind you will have to make your own wrappers for reading/writing to localStorage and finding/editing items in the string as the browser itself will just see this is a string of gibberish. Worth it once implemented though.

jonlepage commented 2 years ago

it a chromium restriction, not related to nwjs

When someone asked the Chromium team members to increase the size, this is what one of them responded:

We don't want people to store large amounts of information in LocalStorage. The API can block a page (and any other pages in your same renderer process) while it loads LocalStorage into memory because it's a synchronous API. Honestly, we'd just plain not support it if we could, but too many developers/sites rely on it. So this is the compromise.

But clearly we don't want you loading hundreds of megs into memory and thus blocking everything in the web browser for extended periods of time.

IndexedDB is a bit easier than WebSQLDatabase and will be ready for prime time before long. WebSQLDatabase isn't that complicated. FileSystem is really the right place to store big files (which is what it sounds like you're doing) and is available in Chrome 9. I suggest you look at these alternatives.

I'm tempted to mark this as a WontFix...

But, IndexedDB might be a good solution for you.

https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API

baconbrad commented 2 years ago

@djmisterjon Yes, it is a won't fix on the upstream. But it is patchable for NW.js. Electron patches this to allow unlimited storage for localStorage already. The performance is still really good past 50 megs. The main reason for the initial strict limit was to prevent abuse so visiting a malicious website didn't immediately max out a person's hard drive upon visiting it. Using IndexedDB has the same limit but the browser will prompt the user for permission to increase it if the limit is reached.