WebClient runs javascript

Well, no. WebClient is an HTTP client, not a web browser.

An HTTP client follows the HTTP spec; the fact that your HTTP requests result in HTML is irrelevant to the client.

A web browser, on the other hand, in addition to being an HTTP client, also knows how to parse HTML responses (and execute JavaScript, etc.).

It seems that what you are looking for is called a “headless browser”, which supports loading HTML and running JavaScript on the DOM, exactly like you need. Headless browsers are also generally quite fast compared to normal browsers, since they don’t need to do any rendering.

There are several headless browsers. HtmlUnit (which can be converted to run on .NET) seems like a good choice, as does envjs (it’s written in JavaScript, which can be embedded in .NET). Unfortunately, I have no experience with either, but they both look super-cool, especially envjs. Update: a nice, more up to date list of headless browsers has been published on GitHub.

There are also other alternatives to the WebBrowser control which may or may not be faster in your case, if you want to stay with a control.

Leave a Comment