YouTube在主页上的动态加载如何工作?
我正在制作一个扩展程序,该扩展名将在主页上的每个视频下放置一个按钮,但是我很快发现,只需使用SelectAll语句就不可能。 Selectall语句唯一的事情是它在主页上检索前3行视频。我认为正在发生的事情是在加载页面后正在加载视频,因此元素在“ document_end”上不存在(这是我的Chrome扩展名将JS/CSS注入页面上的时候)。我会寻找类似活动听众的东西,但解释了为什么会发生这种情况。
I'm making an extension that will put a button under each video on the home page but I found out very quickly that this wouldn't be possible by just using a selectAll statement. The only thing that a selectAll statement does is it retrieves the first 3 rows of videos on the homepage. I think what's happening is there are videos being loaded after the page has loaded thus the elements don't exist at "document_end"(this being when my chrome extension is injecting the js/css onto the page). I would be looking for something like an event listener but an explanation as to why this is happening would be appreciated as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过使用 mutationObserservers 在您的内容脚本中。
示例在下面的MDN Web文档中,您应该能够通过在回调函数中使用
document.queryselectorall()
来调用并查找新元素。You could solve this by using MutationObservers in your content script.
Example from mdn web docs below, you should be able to call and find new elements by using
document.querySelectorAll()
inside the callback function.