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

天大地大妈咪最大 提交于 2019-12-08 12:52:33

问题


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.


回答1:


Check if LSID cookie is set:

chrome.cookies.get({url:'https://accounts.google.com', name:'LSID'}, function(cookie) {
    if (cookie) {
        console.log('Sign-in cookie:', cookie);
    }
});

manifest.json permissions: "cookies", "https://accounts.google.com/"




回答2:


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.



来源:https://stackoverflow.com/questions/38985220/google-chrome-extension-how-to-find-out-if-a-user-has-signed-in-to-the-chrome-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!