Saving localStorage for WebView on macOS 10.11+

I applied WebView in my macOS application and loaded the page into it. When users interact with the page, the changes are saved in localStorage (which is confirmed by making the same changes in Chrome), but it looks like WebViews don’t save localStorage on macOS.

Earlier answers (years ago) indicate the use of a private API, which has since been completely removed. Is there no way at all to save localStorage for WebView on macOS? It seems crazy.

+5
source share
2 answers

The following thread has a workaround that may or may not solve your problem: Javascript / HTML storage options in the file protocol (file: //)

He suggests using window.name to store data through page reloads. This is not safe as the data is not isolated from your frame and may leak to other frames / tabs / domains, but this may solve your problem.

-1
source

You can always set up a simple CoreData repository to modify data and restore it to WebView in ViewWillAppear.

And there is this solution .

-1
source

Source: https://habr.com/ru/post/1269491/


All Articles