Created attachment 462504 [details] test script that is shown the problem IOS16 Safari: LocalStorage is cleared after writing data of more than ~2.5MB. After upgrading on IOS 16 we were faced the problem clearing data in localStorage.When we try to write data that size is more than ~2.5MB or all amount of data more than ~2.5MB the LocalStorage is being cleared without any errors and warnings in Safari. I could not reproduce the problem in other browsers or platforms. Step to reproduce: - Go to IOS 16 Safari - Open any website - try to write data more than ~2.5MB (the attached test script helps you to display the problem) - check your localStorage Actial result: your localStorage is empty Expected result: your localStorage should be filled your data or it should be thrown an exception if quota is exceeded Please consider the problem ASAP. Thank you in advance!
<rdar://problem/100252023>
Pull request: https://github.com/WebKit/WebKit/pull/4758
Committed 255044@main (0297f1253a4f): <https://commits.webkit.org/255044@main> Reviewed commits have been landed. Closing PR #4758 and removing active labels.
Can you share the IOS version where the issue will be fixed? thank you in advance!
I don't think this test script is correct. It measures the string length of all values in LocalStorage. But LocalStorage is persisted, and it's the size of the persisted string that matters for quota computations. Currently in WebKit, LocalStorage string values are persisted as UTF-16 (2 bytes per character)--see the call to SQLiteStatement::bindBlob(StringView) in SQLiteStorageArea::setItem. So I would expect that you could only store 2.5 million characters before exceeding your quota on disk.
Note that Chrome implements LocalStorage in the exact same manner: string values are persisted as UTF-16, so they use 2 bytes per character. However, their quota for LocalStorage is 10 MB (https://chromiumcodereview.appspot.com/21680002), so when you run your test case, you can store 5 million characters. We could possibly address this by discussing whether it's a good idea to bump up our quota as well. However, given the current 5 MB quota, the fact that you can only store 2.5 million characters in your test case is intended and things are working as expected.
Reopened as 255044@main is reverted in https://bugs.webkit.org/show_bug.cgi?id=247767. As Ben mentioned, WebKit stores string in LocalStorage as UTF-16, so it is expected that 5MB quota only allows about 2.5 million characters. The was implemented way before iOS 16, so likely not a regression. However, this could still be a compatibility issue as Safari has different behavior than Chrome and Firefox, so we should keep this bug and figure out how to solve it.
This issue is a regression because localStorage is cleared when the amount of storage is reached more than 2.5 million characters. It could not be reproduced before ios16.
(In reply to Olexiy from comment #8) > This issue is a regression because localStorage is cleared when the amount > of storage is reached more than 2.5 million characters. It could not be > reproduced before ios16. Oh so the regression is "LocalStorage is cleared after quota error", not "LocalStorage throws quota error after writing 2.5 million characters". Updated title to reflect that.
Pull request: https://github.com/WebKit/WebKit/pull/6597
Committed 256863@main (5bc131992783): <https://commits.webkit.org/256863@main> Reviewed commits have been landed. Closing PR #6597 and removing active labels.
It's even more broken in Safari Tech Preview https://bugs.webkit.org/show_bug.cgi?id=252661