Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intercept every request originating from a webpage

Tags:

javascript

Is it possible to intercept every request made from a page using javascript? i.e. Clicking on a link, loading an image, ajax request...

like image 761
akshat Avatar asked Nov 24 '08 17:11

akshat


People also ask

How do you intercept web requests?

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.

How do you intercept request in JavaScript?

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.

What is JavaScript interceptor?

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.


1 Answers

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)

like image 127
Greg Avatar answered Oct 23 '22 06:10

Greg