2

I'm trying to get the userInfo object from chrome.identity.getProfileUserInfo in my popup.js (which is a script used for popup.html) but I am getting the following error:

Uncaught TypeError: Cannot read property 'getProfileUserInfo' of undefined at onload

popup.js

onload = function(){

    chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
        var url = tabs[0].url;
        console.log(url);
    });

    chrome.identity.getProfileUserInfo(function(userInfo)
    {
        console.log(userInfo)
    });
}

manifest.json

{
    "manifest_version": 2,

    "name": "QuickLink",
    "description": "This extension allows you to quickly shorten and/or customize your url",
    "version": "1.0",

    "browser_action": 
    {
        "default_icon": "icon.png",
        "default_popup": "popup.html",
        "default_title": "QuickLink"
    },
    "permissions": 
    [
      "background",
      "activeTab",
      "clipboardWrite",
      "tabs",
      "notifications",
      "identity",
      "runtime"
    ]
}

I believe I have all the right permissions, and my tabs query works just fine, but for some reason, I don't have access to chrome.identity...any ideas why this might be or any work arounds so I can get the userInfo?

Would appreciate any help, thanks!

harir
  • 51
  • 2

2 Answers2

1

As answered in this thread you can only access it with a background script, not a content script.

Eli Richardson
  • 934
  • 7
  • 25
0

It may require providing a "key" value in your manifest as well (if you're trying to get it working locally and it's not working). You can either use the same key as the one you get when you upload your extension to the webstore or try packing an extension to generate a new one (though I couldn't get this second approach working myself).

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147