chrome.pageAction.setIcon 工作不可靠
chrome.pageAction.setIcon does not work reliably
这段代码有什么问题?当我在调试模式下尝试时,它每次都可以更改图标和标题,但是当我在没有调试模式的情况下尝试时,它有时可能不起作用(特别是如果我使用鼠标单击而不是使用多功能框来访问网站)。我相信过滤器可能会导致问题,但我还找不到解决方案。
chrome.webRequest.onCompleted.addListener(
function (details)
{
var url = (new RegExp('^https://([^/@]+@)?([^/@]+)/(.*)').exec(details.url));
var domain = url[2];
if(domainCheck(domain)){
chrome.pageAction.setIcon({tabId: details.tabId, path: 'https_enforced.png'});
chrome.pageAction.setTitle({tabId: details.tabId, title: 'Secure connections enforced'});
}
}, { urls: ["https://*/*"]}
);
提前致谢!
我解决了这个问题,
chrome.webRequest.onCompleted.addListener(
function (details)
{
var url = (new RegExp('^https://([^/@]+@)?([^/@]+)/(.*)').exec(details.url));
var domain = url[2];
if(domainCheck(domain)){
console.log("yesil")
setTimeout(function(){chrome.pageAction.setIcon({tabId: details.tabId, path: 'https_enforced.png'})},100);
setTimeout(function(){chrome.pageAction.setTitle({tabId: details.tabId, title: 'Secure connections enforced'})},100);
}
}, { urls: ["https://*/*"]}
);
这段代码有什么问题?当我在调试模式下尝试时,它每次都可以更改图标和标题,但是当我在没有调试模式的情况下尝试时,它有时可能不起作用(特别是如果我使用鼠标单击而不是使用多功能框来访问网站)。我相信过滤器可能会导致问题,但我还找不到解决方案。
chrome.webRequest.onCompleted.addListener(
function (details)
{
var url = (new RegExp('^https://([^/@]+@)?([^/@]+)/(.*)').exec(details.url));
var domain = url[2];
if(domainCheck(domain)){
chrome.pageAction.setIcon({tabId: details.tabId, path: 'https_enforced.png'});
chrome.pageAction.setTitle({tabId: details.tabId, title: 'Secure connections enforced'});
}
}, { urls: ["https://*/*"]}
);
提前致谢!
我解决了这个问题,
chrome.webRequest.onCompleted.addListener(
function (details)
{
var url = (new RegExp('^https://([^/@]+@)?([^/@]+)/(.*)').exec(details.url));
var domain = url[2];
if(domainCheck(domain)){
console.log("yesil")
setTimeout(function(){chrome.pageAction.setIcon({tabId: details.tabId, path: 'https_enforced.png'})},100);
setTimeout(function(){chrome.pageAction.setTitle({tabId: details.tabId, title: 'Secure connections enforced'})},100);
}
}, { urls: ["https://*/*"]}
);