I have a function that gets the ID of the user currently logged into chrome, however the function only returns 'undefined' even though it does actually get the ID of the user (I have tested that). This is because the function is asynchronous and returns a blank value before the function is able to collect the user ID.
I have tried different ways, but can't seem to find the correct way of writing a call back for the function so it returns the ID of the user:
function getGaia() {
var userId;
chrome.identity.getProfileUserInfo(function(userInfo) {
userId = userInfo.id;
return userId;
});
}
var gaiaId = getGaia();