title: FCM getToken() Failed to register a ServiceWorker for scope error Flutter web
body: <p>In my app, for the web version, I use package <code>firebase 7.3.0</code>.
  I first instantiate Firebase app with a singleton and then instantiate Messaging() as I have done with all other Firebase services I use in my app :</p>
  <pre><code>App firebase = FirebaseWeb.instance.app;
    var firebaseMessaging = messaging();
  </code></pre>
  <p>I have <code>subscribeToTopic()</code> method which first calls <code>getMessagingToken()</code> method as it needs the returned token, but <code>getMessagingToken()</code> throws the error:</p>
  <pre><code>PlatformPushNotificationWeb.getMessagingToken() getToken error: FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:5000/firebase-cloud-messaging-push-scope') with script ('http://localhost:5000/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration). (messaging/failed-service-worker-registration)
  </code></pre>
  <pre><code>Future&lt;String&gt; getMessagingToken() async {
      String token;
  
      await firebaseMessaging.requestPermission().timeout(Duration(seconds: 5)).then((value) {
        print('PlatformPushNotificationWeb.getMessagingToken() requestPermission result is $value');
      }).catchError((e) =&gt; print('PlatformPushNotificationWeb.getMessagingToken() requestPermission error: $e'));
  
      await firebaseMessaging.getToken().then((value) {
        print(' PlatformPushNotificationWeb.getMessagingToken() token is $value');
        token = value;
      }).catchError((e) =&gt; print('PlatformPushNotificationWeb.getMessagingToken() getToken error: $e'));
  
      return token;
    }
  </code></pre>
  <p>I checked and in my <code>index.html</code> firebase-messaging is present:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;title&gt;fixit cloud biking&lt;/title&gt;
    &lt;!--  &lt;meta name=&quot;google-signin-client_id&quot; content=&quot;YOUR_GOOGLE_SIGN_IN_OAUTH_CLIENT_ID.apps.googleusercontent.com&quot;&gt;--&gt;
    &lt;meta name=&quot;google-signin-client_id&quot; content=&quot;xxxxxxxxxx.apps.googleusercontent.com&quot;&gt;
  &lt;!--  &lt;meta http-equiv=&quot;Content-Security-Policy&quot; content=&quot;upgrade-insecure-requests&quot;&gt;--&gt;
  &lt;/head&gt;
  &lt;!--&lt;body&gt;--&gt;
  &lt;body id=&quot;app-container&quot;&gt;
  &lt;script src=&quot;main.dart.js?version=45&quot; type=&quot;application/javascript&quot;&gt;&lt;/script&gt;
  &lt;!-- The core Firebase JS SDK is always required and must be listed first --&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js&quot;&gt;&lt;/script&gt;
  
  &lt;!-- TODO: Add SDKs for Firebase products that you want to use
       https://firebase.google.com/docs/web/setup#available-libraries --&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-auth.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-analytics.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-messaging.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-storage.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-database.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.15.5/firebase-remote-config.js&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Now, the error says <code>'http://localhost:5000/firebase-messaging-sw.js'</code> not <code>firebase-messaging.js</code> as the library in the index.html<code>file.  I noticed that </code>Messaging()<code>is not directly available through firebase app instance as it would be for other services, for Storage would be</code>firebase.storage()`.
  Am I missing to setup something else for messaging?</p>