捕获“来自外部链接呼叫的打开链接”事件

时间:2018-07-27 13:14:21

标签: google-chrome-extension firefox-addon

我正在搜索一个事件,该事件在外部桌面软件(例如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已经运行时,如何捕获外部链接的打开?

感谢您的帮助和问候!

1 个答案:

答案 0 :(得分:0)

由于@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;
  }
});