我正在尝试在回调函数中访问chrome.tabs
以下是代码:
chrome.tabs.sendMessage(tabId, {text: 'validatePage'}, fnValidatePage);
function fnValidatePage(respObj){
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
chrome.tabs.executeScript(null, {
code: 'var srcUrl = "' + tabs[0].url + '";'
}, function() {
chrome.tabs.executeScript(null,{file:'jquery-1.12.2.min.js'},function (){
if(tabs[0].url.indexOf('yellowpages.com') >= 0){
chrome.tabs.executeScript(null,{file:'yellowpages.js'});
}
});
});
});
}
获取以下错误:
Error in response to tabs.query TypeError: Cannot read property 'url' of undefined at Object.callback
出了什么问题,如何在回调函数中获取当前标签页?
的manifest.json:
"permissions": [
"tabs",
"activeTab",
"http://*/*",
"https://*/*",
"<all_urls>"
]