Когда я пытаюсь зарегистрировать своего сервисного работника, это происходит
browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script."
code: "messaging/failed-serviceworker-registration"
message: "Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration)."
stack: "FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).
at http://localhost:3000/_next/1554793056515/page/_error.js:112110:32"
, когда я пытаюсь посмотреть, что содержится в этом _error-файле, он выдал ошибку:
WindowController.prototype.getSWRegistration_ = function () {
var _this = this;
if (this.registrationToUse) {
return this.waitForRegistrationToActivate_(this.registrationToUse);
}
// Make the registration null so we know useServiceWorker will not
// use a new service worker as registrationToUse is no longer undefined
this.registrationToUse = null;
return navigator.serviceWorker
.register(DEFAULT_SW_PATH, {
scope: DEFAULT_SW_SCOPE
}) // <<<< THIS PART
.catch(function (err) {
throw errorFactory.create("failed-serviceworker-registration" /* FAILED_DEFAULT_REGISTRATION */, {
browserErrorMessage: err.message
});
})
.then(function (registration) {
return _this.waitForRegistrationToActivate_(registration).then(function () {
_this.registrationToUse = registration;
// We update after activation due to an issue with Firefox v49 where
// a race condition occassionally causes the service work to not
// install
registration.update();
return registration;
});
});
};
ДаЯ поместил рабочий файл в свою корневую папку, тоже попытался переместить его безрезультатно.Попытался изменить версию Firebase тоже.
Это мой SW-файл
importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js");
firebase.initializeApp({
messagingSenderId: "XXX"
}, "YYY");
const MESSAGING = firebase.messaging();
MESSAGING.setBackgroundMessageHandler(function(payload) {
console.log(
"[firebase-messaging-sw.js] Received background message ",
payload
);
// Customize notification here
var notificationTitle = payload.notification.title;
var notificationOptions = {
body: payload.notification.body,
icon: payload.notification.icon,
image: payload.notification.image,
actions: [
{
click_action: payload.notification.actions.action,
title: payload.notification.actions.title
}
]
};
return self.registration.showNotification(
notificationTitle,
notificationOptions
);
});
Есть идеи?Когда я использую тот же файл в другом проекте, он работает.