Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if HTTP requests are open in browser?

Is there an easy way to detect if an XMLHttpRequest is active in the browser window? Or how many are active? ie. Is there a way to detect if there are any AJAX calls active in my browser window?

Extension of question: Using javascript is there a way I can see if any XMLHttpRequests are open? Such as "window.XMLisActive()" or something like that?

Solution: Ended up writing a wrapper for XMLHttpRequest: gist here

like image 812
kidcapital Avatar asked Feb 13 '12 20:02

kidcapital


People also ask

How do I track HTTP requests in my browser?

To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.

How do I know if browser request is coming?

There is absolutely no way to know with certainty if a request came from a browser or something else making an HTTP request. The HTTP protocol allows for the client to set the User Agent arbitrarily.

How do I see page requests?

Inspecting the HTML Response Try right clicking on a piece of information somewhere on the actual web page itself and clicking “Inspect” or “Inspect Element.” This should automatically jump you to the correct spot in the “Elements” tab of the developer tools and show you the exact HTML markup for that element.

How to check HTTP request headers?

HTTP request headers are easily accessible in the web browser itself. To access them, Open the webpage whose headers have to be checked. Right click and select ‘Inspect’ to open developer tools. Select the network tab and refresh or reload the page. Select any HTTP request from the left panel and the header will be displayed on the right.

How do I test multiple HTTP requests at once?

Nine separate tabs in the HTTP window allow you to store and test multiple messages and switch between them as needed. When the request is defined, press Send to send it to the web server. You can analyze the response immediately in the right-hand pane, which displays the body (shown above) and header info:

How do I send an HTTP request?

The HTTP method of the request (GET, PUT, POST, etc.) and the target URL Nine separate tabs in the HTTP window allow you to store and test multiple messages and switch between them as needed. When the request is defined, press Send to send it to the web server.

What information is included in a HTTP request?

This data is bundled into what’s known as the HTTP request header, and it may include information like the source IP address, user’s browser type (like Mozilla, Chrome, etc.), requested URL, and some additional information.


3 Answers

There is not a way to detect an open connection from JS unless you write a wrapper for XmlHttpRequest (or monkey patch it) that keeps track of opened connections.

Here's kidcapital's monkey patch, not sure if it's perfect, but it's a good start

  (function() {
    var oldOpen = XMLHttpRequest.prototype.open;
    window.openHTTPs = 0;
    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
      window.openHTTPs++;
      this.addEventListener("readystatechange", function() {
          if(this.readyState == 4) {
            window.openHTTPs--;
          }
        }, false);
      oldOpen.call(this, method, url, async, user, pass);
    }
  })();

Note

This does not handle fetch or websockets but you could do something similar in those cases.

like image 155
Juan Mendes Avatar answered Oct 04 '22 15:10

Juan Mendes


You can use FireBug for that.

enter image description here

like image 39
Sarfraz Avatar answered Oct 04 '22 17:10

Sarfraz


By using jQuery, you can keep track if there are open requests with the global event handlers: .ajaxStart() and .ajaxComplete()

A global variable set on ajaxStart and reset on ajaxComplete should do the job.

like image 1
vdeantoni Avatar answered Oct 04 '22 15:10

vdeantoni