问题
It seems that for sessionStorage
, it works differently on Chrome's Incognito Mode vs Safari's Private Browsing and Firefox's Private Window? I can find something on http://www.webdirections.org/blog/webstorage-persistent-client-side-data-storage/ but it doesn't say that Safari's Private Browsing will throw an exception.
The following is how I opened "Private Browsing":
- On Safari on Mac, click "Safari -> Private Browsing" on the menu bar
- On Chrome, use "File -> New Incognito Window"
- On Firefox, use "File -> New Private Window"
and on Safari, sessionStorage
does not work, and if I do the following in the console:
> sessionStorage["foo"] = 123.4
Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
> sessionStorage["foo"]
undefined
but on Chrome or Firefox, sessionStorage
works as usual (as non-private browsing). Is the above accurate as far as sessionStorage
is concerned?
回答1:
Your assessment is practically accurate:
- Safari will just use a quota of
0
in private mode, so all attempts to set a value will fail. This is kinda OK according to the spec, as the spec does not mandate a minimum space requirement. - Chrome and Firefox still allow you to use storage, however private storage is independent from non-private, i.e. setting an item in private mode will not reflect back into non-private mode (important for
localStorage
only).
Please note that other browsers are also free to throw QuotaExceededError
exceptions at any given time, should you go over the quota.
回答2:
Safari latest version (Version 12.0) already have access to sessionStorage without any issue in incognito mode.
回答3:
Safari Pivate mode supports localstorage and SessionStorage.
来源:https://stackoverflow.com/questions/18860098/on-a-browser-sessionstorage-in-safaris-private-browsing-does-not-work-the-same