WP7 WebBrowser Control Woes

Something small, but inherently useful to know. When you use the WebBrowser control in WP7 you don’t get the same behavior when browsing. An example that came up during the development of my application is shown below:

explorerwebbrowser component

The left screenshot is from the native internet explorer while the one on the right is from a sample application I made to test the control. I could not understand what was happening and ended up spending a whole afternoon debugging the network traffic with Fiddler (very useful tool btw). *

The problem was that by default the WebBrowser Control had Scripting disabled. Easy enough you will say; just use the easy to find webBrowser.IsScriptEnabled property. There is a catch here though. Let me quote MSDN:

WebBrowser.IsScriptEnabled Property

Enables or disables scripting. This applies to the next document that is navigated to, not the current document. This property is false by default. Set this property to true to enable scripting, or false to disable scripting.

So beware to set WebBrowser.IsScriptEnabled to true before navigating to the page. Any subsequent navigation retains this value, so you have to manually set it to false if you don’t want scripting in other pages.

PS. If you want to make Fiddler work with the WP7 Emulator see this post.