J Bradley
J Bradley

Reputation: 109

How do I sandbox a web browser control in C#?

I am using a web browser control to view cached web pages "offline". The problem I am running into is that when I load a page, some links obviously want to fetch the data from the internet.

I am not interested in "filling in the blanks" by allowing the page to fulfill any GET requests. I am simply interested in viewing the web page "AS IS" without downloading any missing pieces.

The existing events in the Web Browser control do not provide a simple way to block these requests. I did however try using the "ProgressChanged" event which has arguments for the number of bytes being downloaded (eg: e.CurrentProgress, e.MaximumProgess). If I place a "myBrowser.Stop()" statement in there, this somewhat works but is by no means 100%.

I am looking for an event handler or an API that will allow me to block the outgoing GET requests altogether -- OR -- at least prevent anything downloaded from affecting the original html document.

I found one suggestion of using SHDocVw's FileDownload event handler which I could use to test to see if ActiveDocument = true. If it were false, then I could Cancel the event. I got pretty close to implementing something along this lines but when it came to writing the event handler, I could not find the relevant FileDownloadEventArgs for the handler.

I would greatly appreciate someone's help on this.

Upvotes: 2

Views: 394

Answers (1)

Travis J
Travis J

Reputation: 82267

Parse the static content and remove all script, style, and link elements, any element with a src or href should have those attributes set to null. This will prevent any content from being fetched.

Upvotes: 1

Related Questions