demo · v134
Deduplicated reach measurement
The explainer names cross-site reach measurement as the bug-shaped reason for this feature: when an ad shows on five sites within the same second, five shared-storage worklets all run the same has-reported ? skip : report dance — and race. The shared key is read by five workers concurrently, all see false, all write true, all report. Wrap the read/write in navigator.locks.request() and exactly one wins. Press run race below and watch the deduplication appear or fail depending on whether locks are used.
probing navigator.locks in worklet…
Shared Storage worklets only execute in a fenced-frame / permission-policy context. This page uses real
navigator.locks on the main thread for the lock path; the production worklet snippet appears in the code block below.Race five concurrent workers
5
without locks (pre-134 behaviour)
with navigator.locks (Chrome 134+)
No run yet.
The worklet code
// reach-worklet.js (Chrome 134+)
class Reach {
async run({ user_id }) {
await navigator.locks.request('reach:' + user_id, async () => {
if (await sharedStorage.get('reported:' + user_id)) return;
await sharedStorage.set('reported:' + user_id, '1');
privateAggregation.contributeToHistogram({ bucket: 1n, value: 1n });
});
}
}
register('reach', Reach);