From 054afb09768b87f5553c0a9e4360e43dee4fb8ce Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Fri, 16 Feb 2024 17:16:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96findServiceWorker=E5=86=99?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/game.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/game/game.js b/game/game.js index 9d97c6393..3101a5c49 100644 --- a/game/game.js +++ b/game/game.js @@ -144,12 +144,9 @@ new Promise(resolve => { if (location.protocol.startsWith('http') && 'serviceWorker' in navigator) { let scope = window.location.protocol + '//' + window.location.host + '/'; navigator.serviceWorker.getRegistrations().then(registrations => { - let findServiceWorker = false; - for (let registration of registrations) { - if (registration && registration.active && registration.active.scriptURL == `${scope}service-worker.js`) { - findServiceWorker = true; - } - } + let findServiceWorker = registrations.find(registration => { + return registration && registration.active && registration.active.scriptURL == `${scope}service-worker.js`; + }) navigator.serviceWorker.register(`${scope}service-worker.js`, { updateViaCache: "all", scope,