[英]How to enable a pageAction icon for a chrome extension in incognito mode?
即使在选择“允许进入隐身模式”后,我的扩展程序也会以隐身模式显示,该扩展程序使用pageaction在某些网址中呈现。 background.js具有以下内容。
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's URL contains a 'g' ...
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: 'sears' },
})
],
// And shows the extension's page action.
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
看起来像一个错误,所以我在这里报告: crbug.com/408326
作为解决方法,您可以通过将以下内容添加到清单文件来启用拆分隐身模式 :
"incognito": "split"
遗憾的是, chrome.runtime.onInstalled
未针对隐身模式中的扩展程序触发 ,因此您应该避免在扩展程序以隐身模式运行时使用此事件,如下所示:
if (chrome.extension.inIncognitoContext) {
doReplaceRules();
} else {
chrome.runtime.onInstalled.addListener(doReplaceRules);
}
function doReplaceRules() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// ... add rules
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.