[英]How to catch a request from the network tab with javascript?
When I click on a "Load more" button in the website, there are new variations loaded.当我点击网站中的“加载更多”按钮时,会加载新的变体。 You can spot them on the "Network" tab in the inspector of google chrome
您可以在谷歌浏览器检查器的“网络”选项卡上发现它们
See here the output when I clicked, the new color options are shown看到这里 output 当我点击时,显示了新的颜色选项
Once a request with a status are logged in this "network" tab.一旦带有状态的请求记录在此“网络”选项卡中。 Is it possible to add a listener or some sort to a specific log of this, for example: once the "Rectangle-Copy-14.png" is logged, call a function.
是否可以将侦听器或某种类型添加到特定日志中,例如:一旦记录了“Rectangle-Copy-14.png”,请调用 function。
Asking this for this project but also for in the future, I don't use a lot of javascript in this project but for in the future I will.为这个项目以及未来的这个项目要求这个,我在这个项目中不会使用很多 javascript,但将来我会。
If the browser supports it, you could use the resource timing API.如果浏览器支持,可以使用资源时序API。 I would assume you would have to keep listening to the resources of performance, like:
我假设您必须继续聆听性能资源,例如:
performance.getEntriesByType("resource")
Then you can filter this entries by name or type:然后您可以按名称或类型过滤此条目:
resources.filter(resource => resource.name == "Rectangle-Copy-14.png")
If the filter returns a PerformanceResourceTiming with a responseEnd you can then establish that the resource has been loaded and do whatever after.如果过滤器返回带有 responseEnd 的 PerformanceResourceTiming,那么您可以确定资源已被加载并在之后执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.