Detecting whether a user has been registered or not with the Chrome extension

Is there an easy way to detect from the Chrome extension that the user has logged into their google account or not.

I think there is an unpleasant way to figure this out by loading the html / css / js resource which requires authentication. But I would like to do this in a "clear" way.

thanks and better Victor

+3
source share
2 answers

some discussions were held on the chrome extension mailing list: http://groups.google.com/a/chromium.org/group/chromium-extensions/browse_thread/thread/6e46a3a6e46d9110/

, , Xml- Http google.com , :

: ( -)

var currentUser;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
       if (xhr.readyState == 4) {
               currentUser = null;
               if (xhr.status == 200) {
                       var re = new RegExp(/<b class="?gb4"?>[\s]*([^<]+@[^<]+)<\/b>/i);
                       var m = re.exec(xhr.responseText);
                       if (m && m.length == 2) {
                               currentUser = m[1];
                       }
               }
               console.log("Currently logged user (on google.com): " +
currentUser);
       }
};
xhr.open('GET', 'https://www.google.com/', false);
xhr.send();
+1
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");
        }
    }
});

"identity" .

0

Source: https://habr.com/ru/post/1748462/


All Articles