How to store data in localStorage? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to store data in localStorage?

There's a problem to store data in the localStorage directly via mobile App. It's only enabled from the browser. When I try to do this on the mobile app I get an error: "Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document" https://code.sololearn.com/WBykIlB40AXS/?ref=app

23rd Jul 2022, 11:48 PM
Marcin S
Marcin S - avatar
6 Answers
+ 2
Sorry about the delayed response. To answer you last question. The code snippet I copied from 3WSchools purpose is to check if the browser supports webstorage. But in the this case webview does support webstorage but instead ,as I have said in previous replies, webstorage is disabled. Since it is disabled, my code as is produces uncaught error when ran on using sololearn app on an android device. To solve this I should I used try/catch to take care of the uncaught error. https://code.sololearn.com/WuKC09Uv93bJ/#
31st Jul 2022, 2:51 AM
ODLNT
ODLNT - avatar
+ 1
Unfortunately it not a problem but a choice. Sololearn chose not to enable the use of localStorage via the android app. But for some reason on the iOS app, local storage is available. https://code.sololearn.com/WBEDb4ikkZvP/#
24th Jul 2022, 1:56 AM
ODLNT
ODLNT - avatar
+ 1
Bless your ❤ There is nothing to report. Sololearn uses webview to present their web page on an android device. And because of this they have the ability to enable or disable local storage. They chose to disable sable local storage. https://www.techtarget.com/searchsecurity/definition/Android-Webview
24th Jul 2022, 1:17 PM
ODLNT
ODLNT - avatar
0
I know it does't work and I also reported that but I asked how to fix it or if there's some workaround?
24th Jul 2022, 9:14 AM
Marcin S
Marcin S - avatar
0
But I open your code on Android and instead of going into else scope and displaying message "Sorry, your browser does not support web storage..." I get the console log error "Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document"😕 can you explain why?
26th Jul 2022, 8:08 AM
Marcin S
Marcin S - avatar
0
No problem, it works now, so thanks a lot🙏
31st Jul 2022, 8:48 AM
Marcin S
Marcin S - avatar