[英]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.