Javascript 如何在google chrome扩展应用程序中检测我是否处于匿名模式?

Javascript 如何在google chrome扩展应用程序中检测我是否处于匿名模式?,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,这是chrome扩展应用程序的.js文件,单击扩展中的按钮调用测试函数,下面是扩展的html代码。在隐姓埋名模式和默认chrome模式下,它都会作为false发出警报。我在另一个引用中看到了一个使用布尔变量chrome.extension.InInIncognitoContext来检查这一点的例子。我错了吗?代码有问题吗 function test(){ alert(chrome.extension.inIncognitoContext); if(chrome.extension.inIncog

这是chrome扩展应用程序的.js文件,单击扩展中的按钮调用测试函数,下面是扩展的html代码。在隐姓埋名模式和默认chrome模式下,它都会作为false发出警报。我在另一个引用中看到了一个使用布尔变量chrome.extension.InInIncognitoContext来检查这一点的例子。我错了吗?代码有问题吗

function test(){
alert(chrome.extension.inIncognitoContext);
if(chrome.extension.inIncognitoContext){
   chrome.tabs.query({currentWindow: true, active: true},function(tabs){
      alert(tabs[0].url);
    });
}
}

document.addEventListener('DOMContentLoaded', function() {
    var link = document.getElementById('link');
   // onClick's logic below:
    link.addEventListener('click', function() {
    test();
  });
});
业主对该物业有以下看法:

对于在incognito选项卡内运行的内容脚本,以及在incognito进程内运行的扩展页面,均为True。后者仅适用于具有“拆分”匿名行为的扩展

您的代码在弹出窗口中,这意味着它是一个扩展页面。它不是内容脚本。根据上面的描述,如果清单具有顶级属性incognito:split,则扩展页只能看到isIncognitoContext的真值

你可能已经有了,或者可能什么都没有。根据,跨度是默认值:

扩展和Chrome应用程序的默认值为“跨越”,这意味着它将在单个共享进程中运行

业主对该物业有以下看法:

对于在incognito选项卡内运行的内容脚本,以及在incognito进程内运行的扩展页面,均为True。后者仅适用于具有“拆分”匿名行为的扩展

您的代码在弹出窗口中,这意味着它是一个扩展页面。它不是内容脚本。根据上面的描述,如果清单具有顶级属性incognito:split,则扩展页只能看到isIncognitoContext的真值

你可能已经有了,或者可能什么都没有。根据,跨度是默认值:

扩展和Chrome应用程序的默认值为“跨越”,这意味着它将在单个共享进程中运行


@Xan先生,我的问题不是如何在点击按钮时调用函数,而是要确定我是否处于Ingnto模式。是的,阿普西勒先生correct@apsillers@Murali Mea culpa;我看到了令人不快的内容,没有仔细阅读。反向重复。您的清单中是否有与隐姓埋名相关的内容?您是否也可以发布manifest.json?我对您的“匿名”字段特别感兴趣。@Xan先生,我的问题不是如何在单击按钮时调用函数,而是了解我是否处于“匿名”模式。是的,阿普西勒先生correct@apsillers@Murali Mea culpa;我看到了令人不快的内容,没有仔细阅读。反向重复。您的清单中是否有与隐姓埋名相关的内容?您是否也可以发布manifest.json?我对你的隐姓埋名领域特别感兴趣。
<!doctype html>
<!--
This page is shown when the extension button is clicked, because the
"browser_action" field in manifest.json contains the "default_popup" key with
value "popup.html".
-->
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
  body {
    font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
    font-size: 100%;
  }
  #status {
    /* avoid an excessively wide status text */
    white-space: pre;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 400px;
  }
</style>

<!--
  - JavaScript and HTML must be in separate files: see our Content Security
  - Policy documentation[1] for details and explanation.
  -
  - [1]: https://developer.chrome.com/extensions/contentSecurityPolicy
 -->
<script src="popup.js"></script>
</head>
<body>
<button id= "link" onclick="test()">store the page</button>
</body>
</html>