Get HTML source code from CefSharp web browser
<p>I am using aCefSharp.Wpf.ChromiumWebBrowser (Version 47.0.3.0) to load a web page.  Some point after the page has loaded I want to get the source code.</p>

<p>I have called:</p>

<pre><code>wb.GetBrowser().MainFrame.GetSourceAsync()
</code></pre>

<p>however it does not appear to be returning all the source code (I believe this is because there are child frames).</p>

<p>If I call:</p>

<pre><code>wb.GetBrowser().MainFrame.ViewSource() 
</code></pre>

<p>I can see it lists all the source code (including the inner frames).</p>

<p>I would like to get the same result as ViewSource(). Could some one point me in the right direction please?</p>

<p><strong>Update – Added Code example</strong></p>

<p><em>Note: The address the web browser is pointing too will only work up to and including 10/03/2016. After that it may display different data which is not what I would be looking at.</em></p>

<p>In the frmSelection.xaml file</p>

<pre><code>&lt;cefSharp:ChromiumWebBrowser Name="wb" Grid.Column="1" Grid.Row="0" /&gt;
</code></pre>

<p>In the frmSelection.xaml.cs file</p>

<pre><code>public partial class frmSelection : UserControl
{
    private System.Windows.Threading.DispatcherTimer wbTimer = new System.Windows.Threading.DispatcherTimer();

    public frmSelection()
    {

         InitializeComponent();

         // This timer will start when a web page has been loaded.
         // It will wait 4 seconds and then call wbTimer_Tick which 
         // will then see if data can be extracted from the web page.
         wbTimer.Interval = new TimeSpan(0, 0, 4);
         wbTimer.Tick += new EventHandler(wbTimer_Tick);

         wb.Address = "http://www.racingpost.com/horses2/cards/card.sd?race_id=644222&amp;r_date=2016-03-10#raceTabs=sc_";

         wb.FrameLoadEnd += new EventHandler&lt;CefSharp.FrameLoadEndEventArgs&gt;(wb_FrameLoadEnd);

    }

        void wb_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
        {
            if (wbTimer.IsEnabled)
                wbTimer.Stop();

            wbTimer.Start();
        }

    void wbTimer_Tick(object sender, EventArgs e)
    {
        wbTimer.Stop();
        string html = GetHTMLFromWebBrowser();
    }

    private string GetHTMLFromWebBrowser()
    {
         // call the ViewSource method which will open up notepad and display the html.
         // this is just so I can compare it to the html returned in GetSourceAsync()
         // This is displaying all the html code (including child frames)
            wb.GetBrowser().MainFrame.ViewSource();

         // Get the html source code from the main Frame.
            // This is displaying only code in the main frame and not any child frames of it.
            Task&lt;String&gt; taskHtml = wb.GetBrowser().MainFrame.GetSourceAsync();

            string response = taskHtml.Result;
     return response;
  }

}
</code></pre>