我试图使用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