Is it possible to determine if Chrome is in incognito mode via a user-script?

前端 未结 3 1899
星月不相逢
星月不相逢 2020-12-30 01:13

I asked this question before but didn\'t make it clear that I meant in user script, not in JavaScript from a webpage.So I\'ll be more clear now.

Is it possible to de

3条回答
  •  误落风尘
    2020-12-30 01:17

    To detect whether a window is in incognito mode, check the incognito property of the relevant Tab or Window object. For example:

    var bgPage = chrome.extension.getBackgroundPage();
    
    function saveTabData(tab, data) {
      if (tab.incognito) {
        bgPage[tab.url] = data;       // Persist data ONLY in memory
      } else {
        localStorage[tab.url] = data; // OK to store data
    }
    

    http://code.google.com/chrome/extensions/overview.html

提交回复
热议问题