I have a situation in which I need to monitor all network requests made by a web page. When I mean all network requests, I really mean absolutely all of them, that is:
- all requests made from my web page (script or image downloads, XMLHttpRequest requests and so on...)
- all requests made from scripts that have been downloaded from my web page, including scripts from other domains
In this latter case, if I am talking about the following scenario:
<!-- Let's say my web page is hosted at https://example.com/ -->
<html>
...
<script src="https://otherdomain.com/somescript.js"></script>
...
</html>
If somescript.js downloads stuff from the web, from its own domain or any other domain, I need to monitor that, too.
Is that at all possible?
So far, I tried with a service worker, and it does work, at least to some extent. Surprinsgly, some requests are not actually seen by my service worker. Its registration scope is /.
You could monkey patch
fetchandXMLHttpRequest.prototypebefore your target scripts.An example for
fetch: