Reputation: 751
I'm developing a chrome extension. My background script and content script both get loaded when the page loads, but the problem I am facing is for instance on Facebook or Twitter when I scroll down and the site dynamically adds new content to the page. My background script and content script don't recognize that the page has loaded new content and doesn't do what it is supposed to do.
Is there any way to detect new content and make the background script re-launch?
My background script is set to persistent: true
in the manifest, I was hoping that would do something useful but apparently not. Any help is appreciated. Thanks.
Upvotes: 0
Views: 75
Reputation: 73556
Sites with infinite scroll add new content dynamically to the page without changing its url (that is without using history.pushState/popState) so built-in chrome.webNavigation API won't work.
An established routine in such cases is to use a MutationObserver attached to document.body
or the container element to which the new content is appended.
Alternatively you can add listeners for the events used by the js framework of the site, for example FB.Event on facebook or pjax events on github.
Upvotes: 1