[英]Is it possible to intercept a non-ajax request in browser?
Is it possible to intercept HTTP requests in browser with JavaScript which aren't done through XMLHttpRequest
object (ajax)? 是否可以使用JavaScript拦截浏览器中的HTTP请求,这些请求不是通过XMLHttpRequest
对象(ajax)完成的?
I'm mocking an API server with ember-cli-mirage , which is using pretender . 我正在使用ember-cli-mirage嘲笑一个使用pretender的API服务器。 I need to add file upload (images) to the app. 我需要将文件上传(图像)添加到应用程序。 Mocking upload is no issue since it's done by ajax. 模拟上传没有问题,因为它是由ajax完成的。 But I'm unable to intercept the GET request caused by image tag (non-ajax request) since pretender is only intercepting requests done through XMLHttpRequest
and therefore can't return "uploaded" data. 但是我无法拦截由图像标记(非ajax请求)引起的GET请求,因为伪装者只是拦截通过XMLHttpRequest
完成的请求,因此无法返回“上传”的数据。
Is there anyway I could also intercept non-ajax requests? 无论如何我还可以拦截非ajax请求吗?
If not: What should be considered best practice then? 如果不是:那么最佳做法应该是什么呢? This is what I've considered so far: 这是我到目前为止所考虑的:
I think the only way to do this is to use a service worker . 我认为这样做的唯一方法是使用服务工作者 。
The service workers fetch
event can intercept any kind of request. 服务工作者fetch
事件可以拦截任何类型的请求。 However browser support is not very well yet. 但浏览器支持还不是很好。
您也许可以使用Wireshark来嗅探数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.