How can I enable my chrome extension in incognito mode?

邮差的信 提交于 2020-03-07 07:08:05

问题


I created an extension for Google Chrome and would like to know if it is possible for my extension to be enabled in incognito mode.

Ex: chrome.extension ...... allowedIncognitoAccess = true


回答1:


It's not possible to automatically activate incognito mode for Chrome extensions.

Instead of letting the user figure out where the option can be found, just instruct the user to put a check on the checkbox at the extension.

  • To detect whether incognito is enabled, use the chrome.extension.isAllowedIncognitoAccess method.
  • After showing the instructons to the user, use chrome.tabs.create or chrome.tabs.update to open chrome://extensions/?id=YOUR EXTENSION ID HERE. The extension ID can be read programatically through the chrome.runtime.id property. Chrome recognizes the id query parameter and highlights the specified extension in the list of extensions, as seen in the next picture (notice the gray background):

In terms of code:

chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) {
    if (isAllowedAccess) return; // Great, we've got access

    // alert for a quick demonstration, please create your own user-friendly UI
    alert('Please allow incognito mode in the following screen.');

    chrome.tabs.create({
        url: 'chrome://extensions/?id=' + chrome.runtime.id
    });
});



回答2:


Users may manually enable specific extensions in incognito mode by visiting the extensions settings page.

  • Chrome menu
  • Settings
  • Extensions (on left side navigation bar)
  • Check "Allow in incognito" next to the individual extension to be enabled.

See Manage your extensions in Chrome help.



来源:https://stackoverflow.com/questions/17438354/how-can-i-enable-my-chrome-extension-in-incognito-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!