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?