quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

CROS error when using getToken() for FCM token

Open hunzalashakeel1996 opened this issue 4 years ago • 2 comments

firebase: 8.0.0 react: 16.12.0 OS: windows browser: chrome

const msg = firebase.messaging();
    Notification.requestPermission().then(() => {
      return msg.getToken()
    }).then((data) => {
      console.log('token', data)

    })

above code gives me error on console

Access to fetch at 'https://firebaseinstallations.googleapis.com/v1/projects/https://crm-pu.firebaseio.com/installations' from origin 'http://localhost:3000' 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.

Even when I deploy my react app in Heroku the error remain the same. I registered firebase-messaging-sw.js service worker even receive local notification through showNotification() but when I try to get FCM token it gives error of CORS

hunzalashakeel1996 avatar Nov 06 '20 13:11 hunzalashakeel1996

i am facing the same issue. did you resolved it tho

innv-imtinan avatar May 20 '22 06:05 innv-imtinan

I am struggling with the same issue. The error goes away, If I wait for few minutes and refresh the web application (which in turn raises a new fcm token request)

NagarjunaAddanki avatar Sep 27 '22 05:09 NagarjunaAddanki