title: Firebase Cloud Messaging's getToken() pending in Chrome Extension
body: <p>I want to use Firebase Cloud Messaging to show push notifications in my extension. </p>
  
  <p>I followed the <a href="https://firebase.google.com/docs/cloud-messaging/js/client" rel="nofollow noreferrer">official doc</a> and successfully got the permission, but I am unable to get the Firebase token using <code>messaging.getToken()</code>. The method returns a promise but it is neither resolved nor gives an error.</p>
  
  <p>When I call it in console directly, all I get is a <code>Promise</code> object with <code>Pending</code> status.</p>
  
  <p>I have searched many questions but no solution applied to mine.</p>
  
  <p>Here is the initialization code I have written in <code>background.js</code>:</p>
  
  <pre><code>var config = {
      apiKey: "BWgeK.................MKfP",
      authDomain: "****-*****-******.firebaseapp.com",
      databaseURL: "https://****-*****-******.firebaseio.com",
      projectId: "****-*****-******",
      storageBucket: "****-*****-******.appspot.com",
      messagingSenderId: "************"
  };
  firebase.initializeApp(config);
  
  const messaging = firebase.messaging();
  messaging.usePublicVapidKey("******");
  
  messaging.requestPermission()
      .then(function() {
          //It is printing
          console.log("=== have permission ===");
          return messaging.getToken();
      })
      .then(function(currentToken) {
          //It is not printing
          console.log("== f_token ==", currentToken);
      })
      .catch(function(err) {
          console.log("==== error ====", err);
      });
  </code></pre>
  
  <p>Here is the <code>manifest.json</code> file:</p>
  
  <pre><code>{
      "manifest_version": 2,
      "name": "Chrome Plugin",
      "description": "Chrome Plugin",
      "version": "1.0.0.1",
  
      "icons": {
          "128": "images/small-logo.png"
      },
      "browser_action": {
          "default_icon": "images/small-logo.png",
          "default_popup": "index.html"
      },
      "background": {
          "scripts": ["lib/jquery-3.2.1.min.js","lib/firebase.js", "lib/firebase-app.js","lib/firebase-auth.js", "lib/firebase-messaging.js", "firebase-messaging-sw.js", "src/background.js"],
          "persistent": true
      },
      "content_scripts": [
      {
          "matches": ["https://google.com/*"],
          "js": ["lib/jquery-3.2.1.min.js", "src/content.js"],
          "css": ["css/dialog.css"],
          "run_at": "document_end"
      }],
     "permissions": ["identity", "tabs", "storage", "notifications", "webRequest", "webRequestBlocking", "&lt;all_urls&gt;", "unlimitedStorage"],
     "content_security_policy": "script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'",
     "web_accessible_resources": [
         "css/dialog.css", "css/popup.css", "images/small-logo.png",
         "lib/jquery-3.2.1.min.js", "lib/firebase.js", "lib/firebase-messaging.js", "lib/firebase-app.js", "lib/firebase-auth.js",
         "src/main.js", "src/content.js", "firebase-messaging-sw.js"],
     "oauth2": {
         "client_id": "*******.apps.googleusercontent.com",
         "scopes": ["*******"]
     },
     "gcm_sender_id": "103953800507"
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>=== have permission ===
  </code></pre>
  
  <p>Result of <code>messaging.getToken()</code> in background's console:</p>
  
  <pre><code>Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
  </code></pre>
  
  <p>How can I get this to work?</p>