我試圖使用WebExtensions tabs API獲取當前選項卡網址。Firefox WebExtensions選項卡API如何獲取正在加載的URL
我使用這種方法查詢標籤:
// Get the current window's active tab.
browser.tabs.query({ currentWindow: true, active: true }, function(tabs) {
if (tabs[0].status == 'loading') {
// The user is currently loading a new page.
} else {
// The user is not loading a page.
}
});
如果用戶加載頁面時,我跑的標籤查詢時,tabs[0]
對象如下所示:
{
"id": 114,
"index": 102,
"windowId": 3,
"selected": true,
"highlighted": true,
"active": true,
"pinned": false,
"status": "loading",
"incognito": false,
"width": 1278,
"height": 987,
"audible": false,
"mutedInfo": {
"muted": false
},
"url": "http://example.com/",
"title": "Example Domain",
"favIconUrl": "http://example.com/favicon.ico"
}
你可以看到"status"
設置爲"loading"
。這意味着當頁面加載完成後"url"
可能會改變。
有無論如何知道用戶正在加載什麼頁面?
在Firefox 54.
謝謝,我會研究第一個解決方案。看起來像一個聰明的人。如果有效,我會接受這個答案。 – Harvey
工作很好!謝謝! – Harvey