即使选择“允许在隐身模式”后,使用 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 https://code.google.com/p/chromium/issues/detail?id=408326
作为解决方法,您可以启用分割隐身模式 https://developer.chrome.com/extensions/manifest/incognito通过将以下内容添加到清单文件中:
"incognito": "split"
很遗憾,chrome.runtime.onInstalled https://developer.chrome.com/extensions/runtime#event-onInstalled is 隐身模式下的扩展程序不会被触发 https://code.google.com/p/chromium/issues/detail?id=264963,因此当扩展程序以隐身模式运行时,您应该避免使用此事件,如下所示:
if (chrome.extension.inIncognitoContext) {
doReplaceRules();
} else {
chrome.runtime.onInstalled.addListener(doReplaceRules);
}
function doReplaceRules() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// ... add rules
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)