Everyone knows two things about localStorage . It might be empty, and reading it might throw in a privacy mode. There is a third state that I had never written code for, and it cost new CogniPrep users their first logged-in page:
TypeError: Cannot read properties of null (reading 'getItem')
Enter fullscreen mode
Exit fullscreen mode
Not "storage is empty". Not "access denied". window.localStorage was null . An Android WebView with DOM storage disabled hands you a null property where the object should be, so the obvious line
const stored = localStorage . getItem ( ' theme ' );
Enter fullscreen mode
Exit fullscreen mode
throws a TypeError before any storage policy gets a say. Android WebViews are how in-app browsers render pages, which makes this ordinary traffic rather than an edge case. The error arrived tagged Chrome Mobile WebView.
Why it landed on the worst possible page
CogniPrep forces dark mode on its marketing and auth pages, and respects your preference everywhere else.…