How do I use chrome.tabs.onUpdated.addListener?

為{幸葍}努か 提交于 2019-12-30 03:15:26

问题


I am creating an extension for Chrome. I want to show an alert() with the page URL whenever the user moves from one tab to another, or when the user enters a new URL in a tab.

This is not working:

chrome.tabs.onUpdated.addListener(function(integer tabId, object changeInfo, Tab tab) {
    alert(changeInfo.url);
});

chrome.tabs.onActivated.addListener(function(object activeInfo) {
    // also please post how to fetch tab url using activeInfo.tabid
});

回答1:


Remove integer, object and Tab in the functions signature.

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
   alert(changeInfo.url);
}); 

chrome.tabs.onActivated.addListener(function(activeInfo) {
  // how to fetch tab url using activeInfo.tabid
  chrome.tabs.get(activeInfo.tabId, function(tab){
     console.log(tab.url);
  });
}); 


来源:https://stackoverflow.com/questions/11156479/how-do-i-use-chrome-tabs-onupdated-addlistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!