如果取消对 localStorage 的写入会发生什么?

What happens if a write to localStorage is canceled?

假设我像这样调用本地存储:

window.localStorage.setItem("key", bigJsonObject);

紧接着,用户关闭了他们的网络浏览器。

的结果是什么
window.localStorage.getItem("key") 

bigJsonObject 会被部分写入吗?或者整个写入会失败吗?他们有什么方法可以保证不会有部分写入吗?

参考§4.1 of the "web storage" specification:

The setItem() and removeItem() methods must be atomic with respect to failure. In the case of failure, the method does nothing. That is, changes to the data storage area must either be successful, or the data storage area must not be changed at all.

但是,(历史上)在这方面存在浏览器错误,e.g. some time before Chrome 21 until some time before Chrome 29