我几个月都被困在这个表格上。我正在尝试获取已登录Chrome用户的电子邮件地址。我第一次尝试:
chrome.identity.getProfileUserInfo(function(userInfo) ) but couldn't get a returned email address.
现在我正在尝试使用No Idea博客中的示例: https://noidea.dog/blog/chrome-identity-api
我已将他们的代码复制到我的background.js中。这是我的background.js:
chrome.identity.getProfileUserInfo(function(info) { email = info.email; });
chrome.extension.onMessage.addListener(function(request, sender,
sendResponse) {
sendResponse( {email: email})
});
我修改了"登录按钮"在我的popup.js中:
$('#btnLogin').button().click(function () {
var logged_in_user;
chrome.extension.sendMessage({}, function(response) {
logged_in_user = response.email
});
console.log("Got user:", logged_in_user);
});
这是我的manifest.json的一部分:
"background": {
"scripts": ["background.js"],
"persistant": false
},
"permissions": [
"activeTab",
"identity",
"identity.email",
"http://localhost/*.*"
],
"oauth2":{
"client_id": "koinkhimjmddddjlmfplohggjnnmixxx",
"scopes": [ "email"]
}
当我运行这个时,我得到了用户:undefined。我做错了什么?