Chrome Extension Page Action Icon not enabled in Incognito mode but only when installed from Web Store -
i have chrome extension page action wish users can run both in incognito mode , in regular mode.
the page action open new tabs with:
window.open(url);
i need page icon opens new incognito tab if in incognito mode , regular tab in regular mode. therefore, added following sentence in manifest:
"incognito": "split",
in background.js file of extension, following code enables page action:
chrome.runtime.oninstalled.addlistener(function() { // replace rules ... chrome.declarativecontent.onpagechanged.removerules(undefined, function() { // new rule ... chrome.declarativecontent.onpagechanged.addrules([ { conditions: [ new chrome.declarativecontent.pagestatematcher({ pageurl: { urlmatches: '<a_url_pattern>' }, }) ], // , shows extension's page action. actions: [ new chrome.declarativecontent.showpageaction() ] } ]); }); });
the page action works fine (the page icon enabled both in incognito , in non-incognito mode) if load extension locally. however, after publishing extension in web store, page icon enabled in non-incognito mode.
why have difference in behavior in incognito mode between loading locally or loading published version web store?
btw, before adding "incognito", "split"
in manifest file, page icon enabled both in incognito mode , in normal node in previous published extension, seems "incognito", "split"
, line changed in extension update has it.
update: after further investigation, mismatch in behavior not caused origin of extension (i.e. load unpacked vs. web source), depends on if there incognito window open when click allow in incognito in chrome://extensions.
it seems that, in split mode, if there incognito window open when click allow in incognito, oninstalled
listener fired both incognito , non-incognito contexts. however, if there no incognito window open when click allow in incognito, oninstalled
listener only fired in non-incognito context, page action icon not enabled in incognito context.
this seems chrome bug. workaround bug described in answer this question.
Comments
Post a Comment