2

According to the Crossrider docs, there is currently a webRequest object with the onRequest event, which allows for accessing the request URI, etc., but I could not find any way to inspect the response data. I was wondering if there is a way to actually inspect the response of that request, such as the response headers and possibly the response data. Thanks for the help.

Shlomo
  • 3,763
  • 11
  • 16
Alex G.
  • 31
  • 2

1 Answers1

3

I'm going out on a limb here but I think your after an AJAX request, in which case you are after the appAPI.request API where you can indeed obtain response and header data. The appAPI.webRequest API is like Chrome's webRequest API used "to observe and analyze traffic and to intercept, block, or modify requests in-flight".

If this is not the case, please can you clarify your scenario.

[RESPONSE TO COMMENT]

Let me first clarify that the webRequest API runs before the requests are made (i.e. the browser is requesting the page but has not yet made the actual HTTP request) and hence it's not relevant to talk of response data.

However, since the URL is provided in the details of the webRequest, you can get the response data and headers yourself using the aforementioned appAPI.request API, as follows:

appAPI.ready(function() {
    appAPI.webRequest.monitor.onBeforeNavigate.addListener({
        callback: function(details) {
            appAPI.request.get({
                url: details.requestUrl,
                onSuccess: function(response, additionalInfo) {
                    appAPI.db.async.set(details.requestUrl, {
                        response: response,
                        headers: additionalInfo.headers
                    });
                }
            });
        }
    });
});

NOTE: For this example I have used the new webRequest.monitor API designed to be lightweight specifically for monitoring. It's not currently documented (docs should be completed within the next week or so) but you can start using it already for Chrome, Firefox, and Internet Explorer.

[Disclosure: I am a Crossrider employee]

Shlomo
  • 3,763
  • 11
  • 16
  • Thanks for the response. I am attempting to develop something like a traffic monitor and possibly save the response data. So the page would make a number of different HTTP requests and I was hoping that my extension could fully see the response headers and data as well as the request (which looks like can already be done using webRequest.onRequest event). Thanks. – Alex G. May 02 '14 at 15:19
  • Thanks for the suggestion. In the callback function of the onBeforeNavigate listener, when I call appAPI.request.get, that will actually make another separate request to the details.requestUrl, correct? I was hoping to avoid making any additional requests and simply monitor the requests/responses made and received the the browser. – Alex G. May 05 '14 at 16:52
  • Correct, appAPI.request.get will actually make a separate request to the details.requestUrl, but this is necessary, per the explanation that onBeforeNavigate is triggered before the browser has made the request. – Shlomo May 06 '14 at 12:42