Is it possible to intercept every request made from a page using javascript? i.e. Clicking on a link, loading an image, ajax request...
To intercept HTTP requests, use the webRequest API. This API enables you to add listeners for various stages of making an HTTP request. In the listeners, you can: Get access to request headers and bodies and response headers.
js file (the actual service-worker code): To intercept requests, you attach a fetch event listener to the service worker that calls the respondWith() method and does something with the . request member from the event object: self. addEventListener('fetch', function(event) { event.
Interceptors are code blocks that you can use to preprocess or post-process HTTP calls, helping with global error handling, authentication, logging, and more. In this article, you'll learn how to intercept JavaScript Fetch API calls.
In a word, no. There's no place you can hook into to get all the requests.
Having said that, you can us javascript to place event handlers on the links, look at the src attribute of image tags and so on. There's no "generic" way to hook into all the AJAX requests - it depends on the library you're using.
There are other things to consider, such as CSS background images, Flash (what if a flash file makes a request?).
If possible you should be using the browser itself (e.g. Firebug) or a proxy (e.g. Fiddler) or a packet sniffer (e.g. Ethereal... seems to be WireShark now)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With