6

in firebase-messaging-sw.js

importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js

getting error as "importScripts is not defined"

where to include firebase-messaging-sw.js Js file in angular app ? I have included in scripts/firebase-messaging-sw.js .

In index.html

        <script src="scripts/firebase-messaging.js"></sc

1 Answer 1

5

In your index.html, shouldn't you be referencing firebase-messaging-sw.js and not firebase-message.js? Also, I believe firebase-messaging-sw.js needs to be at the root level (no nesting in script directory). Thus you would have something like the following in index.html...

<script src="firebase-messaging-sw.js">

The service worker script will be loaded and will then import the Firebase scripts from the Firebase CDN.

Sign up to request clarification or add additional context in comments.

2 Comments

yes..I have added <script src="firebase-messaging-sw.js"> at root level and also <script src="gstatic.com/firebasejs/3.5.2/firebase-app.js"></…> <script src="gstatic.com/firebasejs/3.5.2/…> included these two lines in index.html but still getting that error import scripts are not defined. earlier service worker is not registering by <script src="firebase-messaging-sw.js"> adding this script level at root level now service worker is working and able to register.
Thanks I got it working. To all other guys don't get confused. If you are on localhost keep it in the root like /htdocs/firebase-messaging-sw.js or /www/firebase-messaging-sw.js this way you have to place this file into the root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.