修复url带有文件名时serviceWorker注册失败的问题

This commit is contained in:
nonameShijian 2024-05-17 21:56:26 +08:00
parent a4e4998afc
commit 91edb35780
1 changed files with 1 additions and 1 deletions

View File

@ -134,7 +134,7 @@
// 使serviceWorker加载完成后再加载entry.js
if (location.protocol.startsWith("http") && "serviceWorker" in navigator) {
let scope = window.location.protocol + "//" + window.location.host + window.location.pathname;
let scope = (new URL("./", location.href)).toString();
let registrations = await navigator.serviceWorker.getRegistrations();
let findServiceWorker = registrations.find(registration => {
return registration && registration.active && registration.active.scriptURL == `${scope}service-worker.js`;