當前網頁的網址我想從我的default_popup
頁面獲取當前頁面的網址是這樣的:獲取Chrome擴展
chrome.tabs.query({active:true},function(tab){
url = tab.url;
});
而且我已經在manifest.json
文件中註冊該popup.html
頁。然而 我收到錯誤消息:
Uncaught Type Error: Cannot call method 'query' of undefined
我在做什麼錯?
的錯誤你得到意味着該函數'query'沒有了'chrome.tabs'對象上存在。您調用此函數的擴展部分是否具有訪問此函數的權限?你的擴展是否有*選項卡*特權? – user2428118
是的,我的擴展名有標籤特權,我在popup.html頁面內使用上面的chrome.tabs.query()方法,該頁面在manifest.json文件中的browser_action:field中註冊爲default_popup。 –