我正在制作Google扩展程序,其中一部分是在您点击按钮时获取当前网址。我得到的错误是:
Error in response to tabs.query: TypeError: Cannot read property 'url' of undefined
at Object.callback (chrome-extension://enpjjbneobjdmeihjdfpmpenhhkhpkif/popup.js:3:23)
at setURL (chrome-extension://enpjjbneobjdmeihjdfpmpenhhkhpkif/popup.js:2:14)"
这是我的代码
function setURL(){
chrome.tabs.query({'active': true, 'lastFocusedWindow': true},
function(tabs) {
var url = tabs[0].url;
document.getElementById("URL").value = url;
});
}
function clickHandler() {
setTimeout(setURL, 1000);
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById("getURL").addEventListener('click', clickHandler);
});
有谁知道造成这种情况的原因是什么?