The answer above blocks cookies as well. I came up with a makeshift solution (for Windows users, but it should work for Linux in a similar way) to block local storage and allow cookies at the same time:
Open the local storage folder:
%LocalAppData%\Google\Chrome\User Data\Default\Local Storage
The "chrome-" prefixed files are used by chrome and extensions, do not delete them. The "http" prefixed files is what we're after. These files are created by websites to store settings or track your browsing.
In the first step, we are going to "whitelist" local storage data for sites we trust. Select all the files you want to keep, such as http_english.stackexchange.com_0.localstorage, and set their file permissions to "hidden". You'll see why in the next step.
Then create a batch file / shell script that will delete all non-whitelisted local storage data:
del "%LocalAppData%\Google\Chrome\User Data\Default\Local Storage\http*"
This will delete all non-whitelisted storage data while keeping your whitelisted files, because hidden files are ignored by the del command.
Now execute this shell script every time before you start Chrome. An even better solution is to execute the script automatically using the Windows task scheduler, for example once a day. This will regularly clean up local storage and keep websites from tracking you, while still allowing your whitelisted sites to work.
This solution is not perfect because it does not disable local storage completely, however, this is necessary because a lot of sites will not work if local storage is outright blocked. For example, you will not be able to login on some sites or you just get a blank page.
Another solution is the brute force approach: Simply block local storage through file permissions.
- Right click the Local Storage folder -> Properties -> Security Tab -> Advanced
- Select your username, click Edit, and in the permissions deny "creation of new files"
- Test it by creating a new text file in the local storage folder. It should say permission denied.
Again, keep in mind that with this approach, you'll run into problems sooner or later because some sites require local storage to work properly.