Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The script resource is behind a redirect, which is disallowed

I'm implementing firebase messaging but i'm getting a error on console in chrome.

The script resource is behind a redirect, which is disallowed. /firebase-messaging-sw.js Failed to load resource: net::ERR_UNSAFE_REDIRECT

The file /firebase-messaging-sw.js is in public folder and i'm using FCM installation like this https://github.com/firebase/quickstart-js/tree/master/messaging

But the link the authorization is a link like https://09029e3f.ngrok.io/admin/pt/settings/notifications. but the main web site is on main.domain.com

like image 223
Carlos Vieira Avatar asked Apr 10 '17 11:04

Carlos Vieira


1 Answers

Firebase answer and its working

The service worker script (firebase-messaging-sw.js) is expected to be on the absolute path of the application by default. Using the quickstart project, the location will be http://localhost:5000/firebase-messaging-sw.js.

Since you're using a different server for the static files storage, the service worker script location might not be the same or in place. With this, we need to update the service worker registration code implementation and call the service worker script from a different location.

Find the static location of the service worker script. In my case, it is http://localhost:5000/sw/firebase-messaging.sw.js, since I moved the service worker script location inside the sw folder. To verify that it is accessible, try to input the url in the browser address bar and the service worker script code should be displayed. Download the firebase.js script locally from https://www.gstatic.com/firebasejs//firebase.js and call it /firebase.js"> on the web pages that need to show a notification.

Update the firebase-messaging.js script. Find the keywords firebase-messaging-sw.js and , then add the path as prefix. In my case, it is http://localhost:5000/sw/firebase-messaging-sw.js and http://localhost:5000/sw/firebase-cloud-messaging-push-scope.

Many thanks firebase

like image 55
Carlos Vieira Avatar answered Oct 01 '22 04:10

Carlos Vieira