Google chrome extension chrome.identity.onSigningChanged回调未启动
我注册了这个钩子:Google chrome extension chrome.identity.onSigningChanged回调未启动,google-chrome-extension,Google Chrome Extension,我注册了这个钩子: chrome.identity.onSignInChanged.addListener(function (identity) { console.log('identity changed:', identity); }); 问题是这个回调永远不会启动。我允许用户使用以下呼叫使用不同的Google帐户登录: 以下是登录名: runUserLogin() { const self = this; chrome.identity.ge
chrome.identity.onSignInChanged.addListener(function (identity) {
console.log('identity changed:', identity);
});
问题是这个回调永远不会启动。我允许用户使用以下呼叫使用不同的Google帐户登录:
以下是登录名:
runUserLogin() {
const self = this;
chrome.identity.getAuthToken({interactive: true}, function (token) {
if (chrome.runtime.lastError) {
return alert(String(chrome.runtime.lastError));
}
if (!token) {
return alert('no token available.');
}
localStorage.setItem(self.tokenKey, JSON.stringify({token: token}));
self.token = token;
const url = MainDataService.CWS_LICENSE_API_URL + chrome.runtime.id;
const req = new XMLHttpRequest();
req.open('GET', url);
req.setRequestHeader('Authorization', 'Bearer ' + token);
req.onreadystatechange = function () {
if (req.readyState == 4) {
const license = JSON.parse(req.responseText);
self.license = license;
self.updateLogin();
}
};
req.send();
});
}
这里是注销:
onClickLogout() {
const self = this;
const token = this.mds.token;
if (!token) {
return alert('You are not logged in.');
}
chrome.identity.removeCachedAuthToken({token: token}, function () {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
return alert(String(chrome.runtime.lastError));
}
self.mds.token = null;
fetch(`https://accounts.google.com/o/oauth2/revoke?token=${token}`).then(function () {
self.mds.updateLogout();
alert('Successfully logged out.');
})
.catch(function (err) {
alert('Could not log out -> ' + err);
});
});
}
我看到这种讨论:
但是我什么也做不到有人知道为什么chrome.identity.onSigningChanged
回调没有启动吗
每次登录/注销时,我都会看到此窗口,因此它应该可以正常工作:
另外,chrome.identity.getProfileUserInfo()
每次我使用不同的帐户登录时都会给我一个新的/不同的身份,所以这似乎也表明它起作用了