CROS error when using getToken() for FCM token

Discussão em 'Angular' iniciado por Rafi Rahman, Abril 25, 2025.

  1. Rafi Rahman

    Rafi Rahman Guest

    Operating System Windows and MAC

    Environment Angular 18.2.6

    Firebase SDK Version 11.6.0

    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.

    We need fix for this issue.

    Continue reading...

Compartilhe esta Página