11

Using javascript or jquery, is there a way to track the http requests(including headers, parameters, etc.), sent by a webpage? What I want to achieve is something similar to the functionality of the 'network' tab of Google Chrome's developer console. All the solutions I found was either tracking Ajax requests or requests made using javascript(using XMLHttpRequest Object). This functionality should also be cross browser compatible.

9
  • developer.chrome.com/extensions/devtools_network Commented Jun 4, 2015 at 12:21
  • 1
    As an extension or as code running in the browser? Code running in the browser is not going to have access to it. Commented Jun 4, 2015 at 12:22
  • You can check the request into your browser using console please Press F12 Key and click on the Network tab. now reload page you can see all the request and response. and once ajax will fire you can also see the ajax request and response. Commented Jun 4, 2015 at 12:27
  • 1
    Actually what I want is just a javascript function to do this. Not an extension. I need to track the requests sent only by the website which contains this javascript file. Commented Jun 4, 2015 at 12:27
  • @tibzon Check out my 1st and 3rd way! Commented Jun 4, 2015 at 12:28

3 Answers 3

1

You can't track everything.

For example some of the calls in Xmlhttprequest are transparent (301 HTTP codes) and can't be handle by javascript client side.

see the XMLHTTrequest specs: http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send-method

This among a few other reasons. if you want to track the requests of a "webpage" it's better to use the development tools of that browser or packet capturing.

On the userExperience side you can only do very limited things.

Sign up to request clarification or add additional context in comments.

Comments

1

You have three choices.

  1. Make sure you know all the places where a request can get fired, and attach an event to it, say RequestFired. And bind the onRequestFired event in your JavaScript / jQuery code.

  2. Go through the Network Developers document or each browser and based on the browser, execute it. This feature may not be available in older browsers like Internet Explorer 7 and 8.

  3. If it is for a particular server, read the Server Log using a server side script and access it using an endpoint. You can use long polling method and fetch the contents of the log, may be this way:

        // jQuery
        $(document).ready(function () {
          setInterval (function () {
            $("#log").load("/path/to/endpoint.log");
          }, 5000);
        });
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <h3>Logs</h3>
        <div id="log"></div>

Comments

1

It can be done, if you are implementing a single page web-application with a framework like AngularJS. There you can do that using HTTP interceptors.

Other than that, you can only track Ajax requests, but not JavaScript requests.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.