Today, concurrent execution of shared storage worklets in scenarios like cross-site reach measurement can result in duplicate reporting, due to the potential race conditions within the "get() and set()" logic. To address this issue, we propose integrating the Web Locks API into Shared Storage. Specifically, - Introduce navigator.locks.request to the worklet environment. - Introduce { withLock: <resource>} option to all modifier methods. - Introduce a batch modify method: sharedStorage.batchUpdate(methods, options). This method, with the 'withLock' option, allows multiple modifier methods to be executed atomically, enabling use cases where a website needs to maintain consistency while updating data organized across multiple keys.
Explainers: https://github.com/WICG/shared-storage/pull/199