仅授予登录用户访问权限-Chrome扩展程序

时间:2020-08-21 17:37:31

标签: javascript cookies google-chrome-extension

我想仅对登录用户(通过cookie验证)限制对launch.js的访问:

通过这种方式,launch.js可以工作:

  chrome.browserAction.onClicked.addListener(function(e){e.url&&e.url.includes("whatsapp")&&chrome.tabs.executeScript(null,{file:"code/launch.js"})});

但是在实施cookie验证后,它不起作用:

  // Browser Action
  chrome.browserAction.onClicked.addListener(fctContext); 

function fctContext() {
    chrome.cookies.getAll({}, function retornaCookie(x) {
      if (x.length == 2) {
        rodazap();
  
        console.log(x.length);
  
        function rodazap(e) {
          e.url &&
            e.url.includes("whatsapp") &&
            chrome.tabs.executeScript(null, {
              file: "code/launch.js",
            });
        }
      } else {
        alert("User not logged.");
      }
      return x;
    });
  }

0 个答案:

没有答案