I ran into this issue and determined it was because a dependency of our app was throwing an error when trying to access local storage. When the app runs in an iframe in incognito, accessing local storage throws an error. If a dependency does not handle a call to local storage with try / catch, that crashes the app.
The same behavior can be reproduced in the Brave browser, by disabling cookies / local storage.
A good solution would be filing a bug with the library that throws that error (it should be as simple as wrapping that reference in try / catch and ignoring the error).
We also fixed this by adding a proxy for the local storage object that will do the same thing.
<script>
let storageOrUndefined;
try {
storageOrUndefined = window.localStorage;
} catch (e) {
storageOrUndefined = undefined;
}
const isIframe = window !== window.top;
if (isIframe) {
const lsProxy = new Proxy(
{},
{
get: (_, prop, __) => (argument) => {
if (!storageOrUndefined) {
return null;
}
try {
return storageOrUndefined[prop](argument);
} catch (e) {
return null;
}
},
}
);
Object.defineProperty(window, "localStorage", {
value: lsProxy,
configurable: true,
enumerable: true,
writable: false,
});
}
</script>