我正在搜索一个事件,当外部桌面软件,如Outlook,Thunderbird,Messenger App等想要默认浏览器(firefox)打开一个新链接时触发。如果firefox之前被关闭,我可以使用一个解决方案来捕捉这个事件:
// catch page when triggered by link and browser was closed
chrome.runtime.onStartup.addListener(function () {
// search for initial tab
chrome.tabs.query({
active: true,
currentWindow: true,
}, function (tabs) {
var initialTab = tabs[0];
// catch open of files and links when browser was closed
if (initialTab.url != 'chrome://newtab/') {
handleNewUrlRequest(initialTab.id,initialTab.url);
}
});
});但是,当firefox已经在运行时,如何捕捉外部链接的打开呢?
感谢您的帮助和问候!
发布于 2018-08-15 18:05:24
感谢@wOxxOm,我以这样的方式做到了:
// catch page when triggered by link and browser is already open (firefox) step 1
var lastRequest = null;
chrome.webNavigation.onCommitted.addListener(function (details) {
if(details.url == 'about:blank' && details.frameId == 0 && details.parentFrameId == -1 && details.transitionType == 'link') {
lastRequest = details;
}
});
// catch page when triggered by link and browser is already open (firefox) step 2
chrome.webNavigation.onBeforeNavigate.addListener(function (details) {
if(lastRequest && details.frameId == 0 && details.parentFrameId == -1 && details.tabId == lastRequest.tabId && details.windowId == lastRequest.windowId) {
console.log('New Request detected: open new Link in Firefox when Firefox is already open');
lastRequest = null;
}
});https://stackoverflow.com/questions/51558761
复制相似问题