If you use a Frame control and navigate to a URI in WPF 3.5 SP1, you'll end up with instantiating the WebBrowser control under the hood, which is new in WPF 3.5 SP1. In order to get at it, you’ll need to cast the Content property of the Frame to a WebBrowser.  I recently had a situation where I needed to actually get at the DOM itself from the WebBrowser control However, I was initially mystified when I saw that the Document property returned a raw .NET object. What do I do with that?

What you need to do is add a reference to the COM type Microsoft HTML Object Library from Visual Studio. That will create a managed wrapper for the MSHTML.dll.  Then you can cast the object returned by the document property to a mshtml.HTMLDocumentClass.  Then you have full access to the DOM!

Oh, one other gotcha: make sure you don’t do this right after calling Navigate() on your frame, because  Navigate() is asynch. You need to do this after the frame’s ContentRendered event has fired.  And, because ContentRendered fires as soon as the Frame is loaded, it may not yet contain the WebBrowser control, so you need to do some type checking. Here’s a code snippet:

    void moddedFrame_ContentRendered(object sender, EventArgs e)
    {
        if (moddedFrame.Content.GetType() == typeof(WebBrowser))
        {
            WebBrowser webBrowser = (WebBrowser)moddedFrame.Content;
            mshtml.HTMLDocumentClass dom = (mshtml.HTMLDocumentClass)webBrowser.Document;
            Console.Write(dom.body.innerHTML);
        }
    }