注意使用chrome.tabs.onUpdated.addListener需要在manifest.json声明tabs权限
permissions: [‘tabs’]
并且需要重新加载插件,如重新加载还是无法生效,请移除插件重新导入
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
if( changeInfo.url == undefined){return false;}
if(tab.url.indexOf('pinterest.com') > 0){
if (tab.status === 'loading'){
chrome.tabs.sendMessage(tabId,{type:'tabUpdate', tab:tab}, function(response)
{
console.log('来自content的回复:'+response);
});
}
}
});
script_content接收
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
if(request.type == 'tabUpdate'){
typeof(GhandleInject_tabUpdate) == 'function' && GhandleInject_tabUpdate();
}
});
|