0

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();
  • @rpadovani I have tried reading through that! Can you please show me how it's supposed to look with my code snippet? – JamesJameson2456 Aug 02 '16 at 10:02
  • Your question is an absolute exact duplicate of a question that gets asked multiple times per day here. How is your example any different? Read the *accepted answer* on the linked duplicate, not all the other stuff around it. – Jamiec Aug 02 '16 at 10:05
  • @Jamiec I have now literally tried every possible way of writing a callback and I can't get it to work. PLEASE help me? – JamesJameson2456 Aug 02 '16 at 13:27

0 Answers0