最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Chrome extension: How to find out if a user has signed in to the Chrome browser? - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 4

Check 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论