As part of a Google Chrome extension that I'm building I need to be able to tell if a user has signed in to the Google Chrome browser while the extension is enabled.
How can I do this?
Please note that using OAuth2 (and thus, the chrome.identity
API) is beyond the scope of my project so I need to find another way.
EDIT: my question is not a duplicate of this one because the solution in that thread no longer works.
As part of a Google Chrome extension that I'm building I need to be able to tell if a user has signed in to the Google Chrome browser while the extension is enabled.
How can I do this?
Please note that using OAuth2 (and thus, the chrome.identity
API) is beyond the scope of my project so I need to find another way.
EDIT: my question is not a duplicate of this one because the solution in that thread no longer works.
Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Aug 16, 2016 at 22:05 user5508297user5508297 8853 gold badges11 silver badges30 bronze badges 3- chrome.identity is the only api for that. Why do you need another way? – Daniel Herr Commented Aug 17, 2016 at 0:01
- Possible duplicate of Detecting whether user is logged in or not from a Chrome extension – Haibara Ai Commented Aug 17, 2016 at 0:51
- You should clarify whether you mean signed into chrome, e.g. from the chrome://settings page, or just signed into a google account without signing into chrome itself. – kzahel Commented Nov 18, 2017 at 0:37
2 Answers
Reset to default 4Check if LSID
cookie is set:
chrome.cookies.get({url:'https://accounts.google.', name:'LSID'}, function(cookie) {
if (cookie) {
console.log('Sign-in cookie:', cookie);
}
});
manifest.json permissions: "cookies", "https://accounts.google./"
chrome.identity.getAuthToken({interactive: false}, function (token) {
if (!token) {
if (chrome.runtime.lastError.message.match(/not signed in/)) {
console.log("not singed in");
} else {
console.log("singed in");
}
}
});
And don't forget to add "identity"
to permissions.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744910533a4600521.html
评论列表(0条)