gpt4 book ai didi

javascript - 如何在隐身模式下为 chrome 扩展启用 pageAction 图标?

转载 作者:行者123 更新时间:2023-11-29 10:42:47 26 4
gpt4 key购买 nike

即使在选择“允许隐身模式”后,我使用 pageaction 在某些 url 中呈现的扩展程序也不会在隐身模式下显示。 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

作为解决方法,您可以启用 split incognito mode通过将以下内容添加到 list 文件中:

"incognito": "split"

不幸的是,chrome.runtime.onInstallednot fired for extensions in incognito mode ,所以当扩展程序以隐身模式运行时,您应该避免使用此事件,如下所示:

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

关于javascript - 如何在隐身模式下为 chrome 扩展启用 pageAction 图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25536703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com