Description
Operating System
Windows and MAC
Environment (if applicable)
Angular
Firebase SDK Version
11.6.0
Firebase SDK Product(s)
Messaging
Project Tooling
Firebase: 11.6.0
Angular: 18.2.6
OS: Windows and MAC
Browser: All
Detailed Problem Description
navigator.serviceWorker.register('/agent/firebase-messaging-sw.js', {
scope: '/agent/'
}).then(async (registration)=>{
getToken(messaging, {
vapidKey: firebaseConfig.vapidKey,
serviceWorkerRegistration: sw
}).then((currentToken) => {
if (currentToken) {
console.log(currentToken);
}
}).catch(() => {
//
});
})
The above code gives me an error in the console. My web application is hosted under this baseHref ("/agent"), and the service worker file (firebase-messaging-sw.js) is also located under this root ("/domain/agent").
Access to fetch at 'https://firebaseinstallations.googleapis.com/v1/projects/https://crm-pu.firebaseio.com/installations' from origin 'http://ribaac.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Steps and code to reproduce issue
navigator.serviceWorker.register('/agent/firebase-messaging-sw.js', {
scope: '/agent/'
}).then(async (registration)=>{
getToken(messaging, {
vapidKey: firebaseConfig.vapidKey,
serviceWorkerRegistration: sw
}).then((currentToken) => {
if (currentToken) {
console.log(currentToken);
}
}).catch(() => {
//
});
})
