How to detect page title change in Google Chrome from an extension?

后端 未结 4 667
南笙
南笙 2020-12-28 09:44

I\'m creating a Google Chrome extension and I need to detect when a page\'s title changes. The page\'s title is changed like in Twitter: (num) Twitter (see the

4条回答
  •  借酒劲吻你
    2020-12-28 10:24

    Put chrome.tabs.onUpdated.addListener in your background script:

    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
       console.log(changeInfo);
    });
    

    changeInfo is an object which includes title changes, e.g. here:

    Screenshot of changeInfo object in console

    Can then filter on the object so that an action only occurs if changeInfo includes a title change. For additional manipulation, e.g. responding to page title changes with page content / actions, you can send a message to content script from inside the listener after whatever conditions are met.

提交回复
热议问题