3

How can I catch all the AJAX requests that a page makes with a Webbrowser / EmbeddedWB? BeforeNavigate2 unfortunately isn't fired for AJAX requests.

For example: requests which are made when you type in google search bar.

mjn
  • 36,362
  • 28
  • 176
  • 378
  • I'm sure there's a way, but this is a rather big topic. There's no direct AJAX support on the embedded browser, but there are ways of catching certain events. It's up to you how to interpret and translate those events, and find the ones which you need. – Jerry Dodge Sep 06 '13 at 23:38
  • `BeforeNavigate2` is used for when the page is changed. But what you're looking for is any HTTP Request. – Jerry Dodge Sep 06 '13 at 23:40
  • @JerryDodge Nothing wrong at all. Just asking if there is a possibility to catch the requests that javascript makes.. –  Sep 06 '13 at 23:42
  • Take a look at [Add a “hook” to all AJAX requests on a page](http://stackoverflow.com/q/5202296/859646). – JRL Sep 07 '13 at 18:29
  • 1
    I suggest to add the tag for the OS webbrowser control (can't find it at the moment). And a link to its - Microsoft - documentation. – mjn Sep 11 '13 at 06:40
  • 1
    The MSDN Webbrowser Control documentation is here: http://msdn.microsoft.com/en-us/library/aa752040%28v=vs.85%29.aspx – mjn Sep 11 '13 at 07:46
  • 1
    Maybe helpful: [AJAX detection in WebBrowser control](http://social.msdn.microsoft.com/Forums/ie/en-US/5fe3e7a1-b3c7-4083-9a00-7a72bf833a9c/ajax-detection-in-webbrowser-control) – mjn Sep 11 '13 at 08:08
  • 1
    Interesting question. I vote to re-open. – kobik Sep 11 '13 at 08:30

2 Answers2

1

If I were you, I would've injected my own script into every page after it's been loaded. This a script that captures all AJAX requests and informs the application.

Using the following code, you may capture every AJAX request made by jQuery (Haven't tried, but I don't think it works for non-jQuery AJAX requests).

$.ajaxSetup({
    beforeSend: function() {
        // before sending the request
    },
    complete: function() {
        // after request completion
    }
});

It's not even a code, but it can give you a clue for what you want to do.

Surely using this method, you're gonna need to somehow communicate with your application. For instance, I'd use my made up protocol and a new window command so that my Delphi component will be able to capture and parse the event.

As I said there are plenty options here and I'm just giving a clue.

Javid
  • 2,755
  • 2
  • 33
  • 60
  • 1
    @EricSantos: I think it does. I don't have much information about BHOs, but I think it can help you when you want to inform the main application, and of course injecting the code. However, it's better if there's no trouble using the BHO like installing, approving, etc. – Javid Sep 07 '13 at 00:01
  • Ah so you are essentially hooking all the Ajax Requests? Can it get the Post Data aswell? –  Sep 07 '13 at 00:27
1

If the environment is under your control. you can use a custom HTTP proxy (based on Indy for example).

See: Indy's TIdHTTPProxyServer: How to filter requests?

Ajax requests can be detected based on their specific header:

How to differentiate Ajax requests from normal Http requests?


Update: this question on the Microsoft web forum has an accepted answer:

Community
  • 1
  • 1
mjn
  • 36,362
  • 28
  • 176
  • 378