1

Because I cannot use the identity object from inside a content script I try to authenticate through the background-JS.

Content-script:

chrome.runtime.sendMessage({Action: "GetToken"}, function(response)
{
   var token = response.Result; // never gets here
}

background-script:

chrome.runtime.onMessage.addListener(
   function(request, sender, sendResponse)
   {
      if (request.Action === "GetToken")
      {
         chrome.identity.getAuthToken({'interactive': true}, function(token)
         {
            console.log("token:"+token);
            sendResponse({Result: token});
         });
   }
});

I can see in the console of the background-script that the token is received ("token:xxxxxx")

But it never receives the content-script. I expect this to be a threading issue; No error is written to the console. How to get around this mess?

Ole Albers
  • 8,715
  • 10
  • 73
  • 166
  • 4
    possible duplicate of [Chrome Extension Message passing between extension(background) and content script](http://stackoverflow.com/questions/20077487/chrome-extension-message-passing-between-extensionbackground-and-content-scrip) (you just need to `return true` after your call to `getAuthToken`) – rsanchez Feb 21 '14 at 20:32

0 Answers0