0

I am building a chrome extension to keep track of the profiles I visit on LinkedIn.In the new LinkedIn UI most of the calls happen over ajax and a complete page-reload is not happening. Is there any way for my chrome extension to get a call back when the future element is available? I have tried delegate method of jquery it doesn't work for change or load event.

  • 1
    [Is there a JavaScript/jQuery DOM change listener?](//stackoverflow.com/a/39508954) – wOxxOm Feb 07 '17 at 15:16
  • The problem with the above method is that the call back is fired for every addition. Say there are 10 li elements then for every addition of li element i am getting a callback. How will I know when the complete insertion has been done. – Shrihari Balasubramani Feb 07 '17 at 15:23
  • It's site-specific. The link shows that some sites use a pjax:end event that signals the end of all async updates so try finding an event for your site or something else. – wOxxOm Feb 07 '17 at 15:47
  • For example, LinkedIn uses Ember framework, so you can try inspecting `Ember` object in the [DOM context](http://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script) and try finding a way to subscribe to the route/event completion. – wOxxOm Feb 07 '17 at 15:59

1 Answers1

1

The delegate() method of jQuery is deprecated. You can use either on() or ajaxComplete() method of jQuery.

m87
  • 4,445
  • 3
  • 16
  • 31
  • http://stackoverflow.com/questions/14266872/document-ajaxcomplete-doesnt-fire-inside-of-content-script Have you tried using it? doesn't work for me in my content script but works in my console. – Shrihari Balasubramani Feb 07 '17 at 17:32
  • can you please elaborate? – m87 Feb 07 '17 at 17:42
  • When i paste `$( document ).ajaxSuccess(function() { console.log("works only in clonsole"); });` It works in console but when i put the same code in content script of my extension, it doesn't work..Other jquery works – Shrihari Balasubramani Feb 07 '17 at 17:55
  • because you are on a different context. see content script vs. injecting script in other s.o. answers. – Zig Mandel Feb 07 '17 at 22:09