How do I enable the pageAction icon for a chrome extension in incognito mode?

Even after selecting "Allow in incognite mode", my extension that uses pageaction to render in certain URLs is not showing in incognito mode. background.js has the following.

chrome.runtime.onInstalled.addListener(function() {
  // Replace all rules ...
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        // That fires when a page URL contains a 'g' ...
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlContains: 'sears' },
          })
        ],
        // And shows the extension page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });
});

      

+3


source to share


1 answer


Looks like a bug, so I reported it here: crbug.com/408326

As a work in progress, you can enable split incognito mode by adding the following to your manifest file:

"incognito": "split"

      



Unfortunately, it does not fire for extensions in incognito mode , so you should avoid using this event when the extension is running in incognito mode as follows:chrome.runtime.onInstalled

if (chrome.extension.inIncognitoContext) {
    doReplaceRules();
} else {
    chrome.runtime.onInstalled.addListener(doReplaceRules);
}
function doReplaceRules() {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // ... add rules
  });
}

      

+3


source







All Articles