4

My error reporting software is catching JS Web Storage (localStorage and sessionStorage) failures that are consistently on Android devices running Chrome mobile. I am not able to reproduce this error on my own Android device.

The specific error is: TypeError: Cannot read property 'setItem' of null which is caught after I attempt to run localStorage.setItem("storageTest","storageTest")

Any ideas or at other experiences with this problem are greatly appreciated.

4
  • Have you opened the stealth mode of the browser? Commented Sep 19, 2017 at 2:27
  • @toams7 I also have exact same problem in my website visited from Android Chrome Mobile. How did you solve yours?
    – Sallu
    Commented Dec 1, 2017 at 16:06
  • @Sallu I wasn't able to solve the problem, so I built a storage module that attempts to use to web storage but uses cookies as a fallback. Cookies have a size limit, and because my application stores large amounts of JSON locally, my fallback has to save multiple cookies and combine them to read a given document. Here it is if you'd like to use it: gist.github.com/minicreative/8e6bb076907c9b880950b1455f60d10e (written for Angular but easily adapted as you need).
    – toams7
    Commented Dec 2, 2017 at 1:08
  • Cool. thanks a lot. Will check it out. My issue is that my data is also over 4k so cookies wont work.
    – Sallu
    Commented Dec 6, 2017 at 0:33

2 Answers 2

2

i think you need to enable dom storage in your android application

WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
1
  • 3
    Thanks for you response - unfortunately this problem isn't happening in an Android application we have access to, it's happening in the Chrome browser for Android.
    – toams7
    Commented Sep 19, 2017 at 3:46
0

Thanks @Anil, this is the correct answer: Solved issue by enabling the DOM storage.

Kotlin :

val settings = webView.settings
settings.domStorageEnabled = true

Not the answer you're looking for? Browse other questions tagged or ask your own question.