Workaround for a disconnected worker on iOS (another one)

This commit is contained in:
Alexander Zinchuk 2022-01-24 04:41:34 +01:00
parent 11b2d54d05
commit df97f085e1

View File

@ -142,6 +142,7 @@ function makeRequest(message: OriginRequest) {
} }
requestStates.set(messageId, requestState); requestStates.set(messageId, requestState);
promise promise
.catch(() => undefined) .catch(() => undefined)
.finally(() => { .finally(() => {
@ -161,7 +162,14 @@ const startedAt = Date.now();
// Workaround for iOS sometimes stops interacting with worker // Workaround for iOS sometimes stops interacting with worker
function setupIosHealthCheck() { function setupIosHealthCheck() {
window.addEventListener('focus', async () => { window.addEventListener('focus', () => {
void ensureWorkerPing();
// Sometimes a single check is not enough
setTimeout(() => ensureWorkerPing(), 1000);
});
}
async function ensureWorkerPing() {
try { try {
await Promise.race([ await Promise.race([
makeRequest({ type: 'ping' }), makeRequest({ type: 'ping' }),
@ -175,5 +183,4 @@ function setupIosHealthCheck() {
window.location.reload(); window.location.reload();
} }
} }
});
} }