IBrowserDisposeAsync Method |
Namespace: DotNetBrowser.Browser
Task<bool> DisposeAsync( BrowserDisposeOptions browserDisposeOptions )
Exception | Condition |
---|---|
ObjectDisposedException | The IBrowser has already been disposed. |
ConnectionClosedException | The connection to the Chromium engine is closed. |
If the currently loaded web page registers the onbeforeunload JavaScript event and the given options tell the browser to fire the beforeunload event, then this method will not dispose the browser right away.
The BeforeUnloadHandler will be invoked in this case and if the handler tells the browser to stay on the web page, then the browser will not be disposed.
The following example demonstrates how to dispose the browser instance as if a user manually clicking the close button of the tab/window.
browser.DisposeAsync(new BrowserDisposeOptions(){BeforeUnloadEventHandled = true});
If the browser is already disposed, then this method does nothing.