Add a bit of jitter

pull/27326/head
Travis Ralston 2024-04-18 16:49:38 -06:00
parent af1ba39f20
commit 9494257745
1 changed files with 3 additions and 0 deletions

View File

@ -63,6 +63,9 @@ self.addEventListener("fetch", (event: FetchEvent) => {
// Figure out which homeserver we're communicating with
const csApi = url.substring(0, url.indexOf("/_matrix/media/v3"));
// Add jitter to reduce request spam, particularly to `/versions` on initial page load
await new Promise<void>(resolve => setTimeout(() => resolve(), Math.random() * 10));
// Locate our access token, and populate the fetchConfig with the authentication header.
// @ts-expect-error - service worker types are not available. See 'fetch' event handler.
const client = await self.clients.get(event.clientId);