[英]How to know if a new tab is opened by user click on new tab button?
在Firefox WebExtensions中,如何知道以新的方式打開新標簽頁?
<a href="http://www.google.com/">
類的鏈接?
注意:我不在乎
window.open()
是否打開新標簽頁
我發現,在chrome.tabs.Tab.onCreated
回調中,傳入了一個參數,假定它名為firefoxTab
:
about:newtab
<a href="" target="_blank">
打開的選項卡,其URL about:blank
但是 ,有一個例外,如果通過單擊“ +”打開Firefox啟動后的第二個選項卡,則其URL將是about:blank
,而不是about:newtab
。 我認為這是Firefox的缺陷,已經在Bugzilla上發布了一個錯誤。
同時,還有其他方法可以做到這一點嗎?
我可以確認在Firefox 52.0中會發生這種情況(在Nightly上進行測試,Firefox 55.0a1產生了類似的結果)。
重新啟動后首次單擊+
發生的事件是:
tabs.onUpdated -> arg[0]= 1 :: arg[1]= Object { status: "loading" } :: arg[2]= Object { id: 1, index: 1, windowId: 1, selected: false, highlighted: false, active: false, pinned: false, status: "complete", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: { muted: false}, cookieStoreId: "firefox-default", url: "about:blank", title: "New Tab"}
tabs.onActivated -> arg[0]= Object { tabId: 1, windowId: 1 }
tabs.onHighlighted -> arg[0]= Object { tabIds: Array[1], windowId: 1 }
tabs.onCreated -> arg[0]= Object { id: 1, index: 1, windowId: 1, selected: true, highlighted: true, active: true, pinned: false, status: "complete", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: { muted: false}, cookieStoreId: "firefox-default", url: "about:blank", title: "New Tab"}
tabs.onUpdated -> arg[0]= 1 :: arg[1]= Object { status: "loading", url: "about:newtab" } :: arg[2]= Object { id: 1, index: 1, windowId: 1, selected: true, highlighted: true, active: true, pinned: false, status: "complete", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: { muted: false}, cookieStoreId: "firefox-default", url: "about:newtab", title: "New Tab"}
webNavigation.onBeforeNavigate -> arg[0]= Object { url: "about:newtab", timeStamp: 1489473167445, frameId: 0, parentFrameId: -1, tabId: 1 }
webNavigation.onCommitted -> arg[0]= Object { url: "about:newtab", timeStamp: 1489473167466, frameId: 0, parentFrameId: -1, tabId: 1, transitionType: "link", transitionQualifiers: Array[0] }
webNavigation.onDOMContentLoaded -> arg[0]= Object { url: "about:newtab", timeStamp: 1489473167718, frameId: 0, parentFrameId: -1, tabId: 1 }
tabs.onUpdated -> arg[0]= 1 :: arg[1]= Object { status: "complete" } :: arg[2]= Object { id: 1, index: 1, windowId: 1, selected: true, highlighted: true, active: true, pinned: false, status: "complete", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: { muted: false}, cookieStoreId: "firefox-default", url: "about:newtab", title: "New Tab"}
webNavigation.onCompleted -> arg[0]= Object { url: "about:newtab", timeStamp: 1489473167914, frameId: 0, parentFrameId: -1, tabId: 1 }
tabs.onUpdated -> arg[0]= 1 :: arg[1]= Object { status: undefined } :: arg[2]= Object { id: 1, index: 1, windowId: 1, selected: true, highlighted: true, active: true, pinned: false, status: "complete", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: { muted: false}, cookieStoreId: "firefox-default", url: "about:newtab", title: "New Tab"}
第二次單擊+
的事件是(是的,事件明顯更少,並且沒有webNavigation
事件):
tabs.onActivated -> arg[0]= Object { tabId: 2, windowId: 1 }
tabs.onHighlighted -> arg[0]= Object { tabIds: Array[1], windowId: 1 }
tabs.onCreated -> arg[0]= Object { id: 2, index: 2, windowId: 1, selected: true, highlighted: true, active: true, pinned: false, status: "complete", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: {"muted: false}, cookieStoreId: "firefox-default", url: "about:newtab", title: "New Tab"}
隨后單擊+
導致類似事件。 有時會觸發其他事件。 此外,還會根據about:newtab
頁面的內容觸發更多事件。
相反,單擊<a href="" target="_blank">
時,會發生許多其他事件。 只是tabs.onCreated
事件是:
tabs.onCreated -> arg[0]= Object { id: 3, index: 2, windowId: 1, selected: true, highlighted: true, active: true, pinned: false, status: "loading", incognito: false, width: 1098, height: 812, audible: false, mutedInfo: {"muted: false}, cookieStoreId: "firefox-default", url: "about:blank", title: "Connecting…"}
如果您想區分,似乎可以查看tabs.onCreated
事件中提供的title
和url
。 對於鏈接,您具有:
url: "about:blank", title: "Connecting…"
要單擊+
您可以使用以下兩個選項之一:
url: "about:blank", title: "New Tab" //First `+`
url: "about:newtab", title: "New Tab" //Subsequent `+`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.