title: Firebase Cloud Messaging without hosting (Web/JavaScript)
body: <p>When working through the official video tutorial for Firebase Cloud Messaging, I am not able to get a messaging token without hosting the application.</p>
  
  <p>Here is my <code>app.js</code> file:</p>
  
  <pre><code>/* global firebase */
  
  // Initialize Firebase
  var config = {
    apiKey: 'AIzaSyBYfb9HAi_oE-PKqFNkRQcxAgLU-nm8sIE',
    authDomain: 'web-quickstart-c0309.firebaseapp.com',
    databaseURL: 'https://web-quickstart-c0309.firebaseio.com',
    projectId: 'web-quickstart-c0309',
    storageBucket: 'web-quickstart-c0309.appspot.com',
    messagingSenderId: '713880824056'
  }
  firebase.initializeApp(config)
  
  const messaging = firebase.messaging()
  messaging.requestPermission()
    .then(() =&gt; {
      console.log('Permission granted.')
      return messaging.getToken()
        .then(token =&gt; {
          console.log('messaging token test:', token)
          return token
        })
        .catch(error =&gt; {
          console.log('messaging error:', error)
        })
    })
    .then(token =&gt; {
      console.log('permission token test:', token)
    })
    .catch(error =&gt; {
      console.log('permission error:', error)
    })
  </code></pre>
  
  <p>I have a <code>firebase-messaging-sw.js</code> file in my root directory.</p>
  
  <p>When I load the <code>index.html</code> file directly in my browser and accept the dialog, I receive an undefined value for the token. The full console output is:</p>
  
  <pre><code>16:20:35.744 app.js:17 Permission granted.
  16:20:35.750 app.js:20 messaging token test: null
  16:20:35.751 app.js:28 permission token test: null
  </code></pre>
  
  <p>If I host the application by editing the <code>firebase.json</code> file to read:</p>
  
  <pre><code>{
    "hosting": {
      "public": "./"
    }
  }
  </code></pre>
  
  <p>And then run <code>firebase serve -p 8081</code>, open <code>http://localhost:8081</code>, and accept the dialog, I do receive a token. The full output is:</p>
  
  <pre><code>16:23:42.902 app.js:17 Permission granted.
  16:23:43.059 app.js:20 messaging token test: eyd1EaFwULQ:APA91bGUZr9fAGcCaYVtXTPjk55AmpWLNdaqGapMa1S1GWTYeJwtJraEKuhAPpSM-v-2xPaSJQgTKRVosTN-0KRPHCccjdRZNDkegtW2HMC_mSbdap9h5TeH7KKQSbN4QrjVmIl7VZlu
  16:23:43.060 app.js:28 permission token test: eyd1EaFwULQ:APA91bGUZr9fAGcCaYVtXTPjk55AmpWLNdaqGapMa1S1GWTYeJwtJraEKuhAPpSM-v-2xPaSJQgTKRVosTN-0KRPHCccjdRZNDkegtW2HMC_mSbdap9h5TeH7KKQSbN4QrjVmIl7VZlu
  </code></pre>
  
  <p>Is this a documented constraint? Is there a way to receive a token without hosting the application?</p>