Chrome Extension on Facebook with Dynamic Posts

陌路散爱 提交于 2020-01-06 08:42:05

问题


Sorry, I think this post probably exists but I couldn't find it. Maybe I am using the wrong words.

I am making a Chrome extension that looks at Facebook posts and does something to them. My Content Scripts gets the posts correctly, but the new ones that are generated as the user scrolls down are not captured since they came later. I tried hooking into an ajaxComplete handler, but that didn't work (Chrome-extension Javascript to detect dynamically-loaded content) I am not sure if I did something wrong or if this isn't what I want.

So, how can I detect these new posts and change the contents of them before the user notices? Any tips are appreciated.

Thanks!


回答1:


You should be watching for DOM mutation events.

See this canonical question and its answer.

Note that DOMSubtreeModified and the like are considered deprecated, and DOM Mutation observers are the modern way.

You could also take a look at Mutation Summary library that's more friendly to use.



来源:https://stackoverflow.com/questions/24590970/chrome-extension-on-facebook-with-dynamic-posts

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