Chromium webBrowser navigation methods
<p>I have added a Chromium WebBrowser to my C# application using the CefSharp library, and now want to add functionality to a 'Back' button, that will allow the user to navigate to the previous page.</p>
<p>As I understand, this would be done with the following line:</p>
<pre><code>browser.WebBrowser.Back();
</code></pre>
<p>However, if I just write this line in the method that is called when the 'Back' button is pressed, then an exception is thrown, and my application breaks.</p>
<p>The exception says:</p>
<blockquote>
<p>Exception was unhandled</p>
<p>An unhandled exception of type 'System.Exception' occurred in CefSharp.dll</p>
<p>Additional information: lBrowser instance is null. Browser has likely not finished initializing or is in the process of disposing.</p>
</blockquote>
<p>Why am I getting this exception?
If I hover my cursor over the line that the exception occurs on, a message pops up which says:</p>
<blockquote>
<p>(extension) void lWebBrowser.Back()</p>
<p>Navigates back, must check lWebBrowser.CanGoBack before calling this method.</p>
</blockquote>
<p>But, if I then move this line inside an <code>if</code> statement that checks the value of <code>lWebBrowser.CanGoBack</code> first, i.e.</p>
<pre><code>if(browser.WebBrowser.CanGoBack){
    browser.WebBrowser.Back();
}
</code></pre>
<p>then although my application will run, <code>CanGoBack</code> always appears to be false- any time I press the 'Back' button, the debug shown in my console indicates that it is false... but if try to assign it a value of <code>true</code> anywhere (i.e. when the user navigates to another page- so there is a page to go back to), for example:</p>
<pre><code>browser.WebBrowser.CanGoBack = true;
</code></pre>
<p>I get a compile error which says:</p>
<blockquote>
<p>Property or indexer 'lWebBrowser.CanGoBack' cannot be assigned to -- it is read only</p>
</blockquote>
<p>So how can I force the browser to navigate back a page when the user clicks the 'back' button?</p>