facebookgoogle-chrome-extensiononupdate

How to find if web page got appended using chrome extension


I am new to chrome extension and I am trying to find whether page content got appended.

For E.g. in Facebook, we can see the content will appended automatically when the user scroll down the page.

I have the following code in background.js

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {

   alert("page is appending....");

});

The above code is expected to fire when the page got updated. But, I am seeing that it is getting called only for few times. Not always.

Or Am I making any mistake here ?

My requirement is, whenever the web page appended in facebook, I have to do get the page content and obtain few string from the same.

Thanks in advance.


Solution

  • Your onUpdated event is in the chrome.tabs namespace on purpose, it listens the updates of tab's general attributes like: the tab pinned, the favicon changed, the URL changed, see the documentation (also check the update() method). So this way is not workable. Instead listen the DOM tree change with DOMSubtreeModified event or MutationObserver.