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();
});
});
this is my .js file for the chrome extension application where i am calling the test() function on clicking a button in the extension(below is the html code of the extension). In both incognito mode and default chrome it is alerting as false. I have a seen in another reference to use the boolean variable chrome.extension.inIncognitoContext to check this. Am I wrong ,are is there any problem with the code
<!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>