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
orchrome.tabs.update
to openchrome://extensions/?id=YOUR EXTENSION ID HERE
. The extension ID can be read programatically through thechrome.runtime.id
property. Chrome recognizes theid
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
});
});