Click or drag to resize

WebBrowserExtensions Class

Version 102.0.100
WebBrowser extensions - These methods make performing common tasks easier.
Inheritance Hierarchy
SystemObject
  CefSharpWebBrowserExtensions

Namespace:  CefSharp
Assembly:  CefSharp (in CefSharp.dll) Version: 102.0.100.0 (102.0.100.0)
Syntax
public static class WebBrowserExtensions

The WebBrowserExtensions type exposes the following members.

Properties
  NameDescription
Public propertyStatic memberEncodeScriptParam
Function used to encode the params passed to [!:ExecuteScriptAsync(IWebBrowser, string, object[])], [!:EvaluateScriptAsync(IWebBrowser, string, object[])] and [!:EvaluateScriptAsync(IWebBrowser, TimeSpan?, string, object[])] Provide your own custom function to perform custom encoding. You can use your choice of JSON encoder here if you should so choose.
Top
Methods
  NameDescription
Public methodStatic memberAddWordToDictionary(IBrowser, String)
Add the specified word to the spelling dictionary.
Public methodStatic memberAddWordToDictionary(IChromiumWebBrowserBase, String)
Add the specified word to the spelling dictionary.
Public methodStatic memberBack(IBrowser)
Navigates back, must check CanGoBack before calling this method.
Public methodStatic memberBack(IChromiumWebBrowserBase)
Navigates back, must check CanGoBack before calling this method.
Public methodStatic memberCloseDevTools(IBrowser)
Explicitly close the developer tools window if one exists for this browser instance.
Public methodStatic memberCloseDevTools(IChromiumWebBrowserBase)
Explicitly close the developer tools window if one exists for this browser instance.
Public methodStatic memberCopy(IBrowser)
Execute Copy on the focused frame.
Public methodStatic memberCopy(IChromiumWebBrowserBase)
Execute Copy on the focused frame.
Public methodStatic memberCut(IBrowser)
Execute Cut on the focused frame.
Public methodStatic memberCut(IChromiumWebBrowserBase)
Execute Cut on the focused frame.
Public methodStatic memberDelete(IBrowser)
Execute Delete on the focused frame.
Public methodStatic memberDelete(IChromiumWebBrowserBase)
Execute Delete on the focused frame.
Public methodStatic memberDisposeDevToolsContext
Dispose of the DevTools Context (if any). Used in conjunction with CefSharp.Puppeteer
Public methodStatic memberEvaluateScriptAsPromiseAsync(IBrowser, String, NullableTimeSpan)
Evaluate Javascript in the context of this Browsers Main Frame. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript. The result of the script execution in javascript is Promise.resolve so even no promise values will be treated as a promise. Your javascript should return a value. The javascript will be wrapped in an Immediately Invoked Function Expression. When the promise either trigger then/catch this returned Task will be completed.
Public methodStatic memberEvaluateScriptAsPromiseAsync(IWebBrowser, String, NullableTimeSpan)
Evaluate Javascript in the context of the MainFrame of the ChromiumWebBrowser. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript. The result of the script execution in javascript is Promise.resolve so even no promise values will be treated as a promise. Your javascript should return a value. The javascript will be wrapped in an Immediately Invoked Function Expression. When the promise either trigger then/catch this returned Task will be completed.
Public methodStatic memberEvaluateScriptAsPromiseAsync(IFrame, String, NullableTimeSpan, String)
Evaluate Javascript in the context of this Browsers Main Frame. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript. The result of the script execution in javascript is Promise.resolve so even no promise values will be treated as a promise. Your javascript should return a value. The javascript will be wrapped in an Immediately Invoked Function Expression. When the promise either trigger then/catch this returned Task will be completed.
Public methodStatic memberEvaluateScriptAsync(IChromiumWebBrowserBase, String, Object)
Evaluate some Javascript code in the context of this WebBrowser. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript This simple helper extension will encapsulate params in single quotes (unless int, uint, etc)
Public methodStatic memberEvaluateScriptAsync(IBrowser, String, NullableTimeSpan, Boolean)
Evaluate some Javascript code in the context of the MainFrame of the ChromiumWebBrowser. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript
Public methodStatic memberEvaluateScriptAsync(IChromiumWebBrowserBase, NullableTimeSpan, String, Object)
Evaluate Javascript code in the context of this WebBrowser using the specified timeout. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript This simple helper extension will encapsulate params in single quotes (unless int, uint, etc).
Public methodStatic memberEvaluateScriptAsync(IChromiumWebBrowserBase, String, NullableTimeSpan, Boolean)
Evaluate Javascript in the context of this Browsers Main Frame. The script will be executed asynchronously and the method returns a Task encapsulating the response from the Javascript
Public methodStatic memberExecuteScriptAsync(IBrowser, String)
Execute Javascript in the context of this Browser Main Frame. As the method name implies, the script will be executed asynchronously, and the method therefore returns before the script has actually been executed.
Public methodStatic memberExecuteScriptAsync(IChromiumWebBrowserBase, String)
Execute Javascript in the context of this Browsers Main Frame. As the method name implies, the script will be executed asynchronously, and the method therefore returns before the script has actually been executed.
Public methodStatic memberExecuteScriptAsync(IBrowser, String, Object)
Execute Javascript code in the context of this WebBrowser. As the method name implies, the script will be executed asynchronously, and the method therefore returns before the script has actually been executed. This simple helper extension will encapsulate params in single quotes (unless int, uint, etc)
Public methodStatic memberExecuteScriptAsync(IChromiumWebBrowserBase, String, Object)
Execute Javascript code in the context of this Browser. As the method name implies, the script will be executed asynchronously, and the method therefore returns before the script has actually been executed. This simple helper extension will encapsulate params in single quotes (unless int, uint, etc)
Public methodStatic memberExecuteScriptAsyncWhenPageLoaded
Execute Javascript code in the context of this Browsers Main Frame. This extension method uses the LoadingStateChanged event. As the method name implies, the script will be executed asynchronously, and the method therefore returns before the script has actually been executed.
Public methodStatic memberFind(IBrowser, String, Boolean, Boolean, Boolean)
Search for text within the current page.
Public methodStatic memberFind(IChromiumWebBrowserBase, String, Boolean, Boolean, Boolean)
Search for text within the current page.
Public methodStatic memberForward(IBrowser)
Navigates forward, must check CanGoForward before calling this method.
Public methodStatic memberForward(IChromiumWebBrowserBase)
Navigates forward, must check CanGoForward before calling this method.
Public methodStatic memberGetBrowserHost
Shortcut method to get the browser IBrowserHost.
Public methodStatic memberGetCookieManager
Gets the default cookie manager associated with the IChromiumWebBrowserBase instance.
Public methodStatic memberGetFocusedFrame
Returns the focused frame for the browser window.
Public methodStatic memberGetMainFrame
Returns the main (top-level) frame for the browser window.
Public methodStatic memberGetRequestContext
Gets the RequestContext associated with the IChromiumWebBrowserBase instance.
Public methodStatic memberGetScriptForJavascriptMethodWithArgs
Transforms the methodName and arguments into valid Javascript code. Will encapsulate params in single quotes (unless int, uint, etc)
Public methodStatic memberGetSourceAsync(IBrowser)
Public methodStatic memberGetSourceAsync(IChromiumWebBrowserBase)
Public methodStatic memberGetTextAsync(IBrowser)
Public methodStatic memberGetTextAsync(IChromiumWebBrowserBase)
Public methodStatic memberGetZoomLevelAsync(IBrowser)
Asynchronously gets the current Zoom Level.
Public methodStatic memberGetZoomLevelAsync(IChromiumWebBrowserBase)
Asynchronously gets the current Zoom Level.
Public methodStatic memberLoadHtml(IChromiumWebBrowserBase, String, Boolean)
Loads html as Data Uri See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs for details If base64Encode is false then html will be Uri encoded.
Public methodStatic memberLoadHtml(IFrame, String, Boolean)
Loads html as Data Uri See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs for details If base64Encode is false then html will be Uri encoded.
Public methodStatic memberLoadHtml(IWebBrowser, String, String)
Registers and loads a ResourceHandler that represents the HTML content.
Public methodStatic memberLoadHtml(IWebBrowser, String, String, Encoding, Boolean)
Registers and loads a ResourceHandler that represents the HTML content.
Public methodStatic memberLoadUrlAsync
See LoadUrlAsync(String) for details
Public methodStatic memberLoadUrlWithPostData(IBrowser, String, Byte, String)
Creates a new instance of IRequest with the specified Url and Method = POST and then calls LoadRequest(IRequest).
Public methodStatic memberLoadUrlWithPostData(IChromiumWebBrowserBase, String, Byte, String)
Creates a new instance of IRequest with the specified Url and Method = POST and then calls LoadRequest(IRequest).
Public methodStatic memberPaste(IBrowser)
Execute Paste on the focused frame.
Public methodStatic memberPaste(IChromiumWebBrowserBase)
Execute Paste on the focused frame.
Public methodStatic memberPrint(IBrowser)
Opens a Print Dialog which if used (can be user cancelled) will print the browser contents.
Public methodStatic memberPrint(IChromiumWebBrowserBase)
Opens a Print Dialog which if used (can be user cancelled) will print the browser contents.
Public methodStatic memberPrintToPdfAsync(IBrowser, String, PdfPrintSettings)
Asynchronously prints the current browser contents to the PDF file specified. The caller is responsible for deleting the file when done.
Public methodStatic memberPrintToPdfAsync(IChromiumWebBrowserBase, String, PdfPrintSettings)
Asynchronously prints the current browser contents to the PDF file specified. The caller is responsible for deleting the file when done.
Public methodStatic memberRedo(IBrowser)
Execute Redo on the focused frame.
Public methodStatic memberRedo(IChromiumWebBrowserBase)
Execute Redo on the focused frame.
Public methodStatic memberRegisterAsyncJsObject Obsolete.

Asynchronously registers a Javascript object in this specific browser instance.

Only methods of the object will be availabe.

Public methodStatic memberRegisterJsObject Obsolete.
Registers a Javascript object in this specific browser instance.
Public methodStatic memberRegisterResourceHandler
Register a ResourceHandler. Can only be used when browser.ResourceHandlerFactory is an instance of DefaultResourceHandlerFactory.
Public methodStatic memberReload(IChromiumWebBrowserBase)
Reloads the page being displayed. This method will use data from the browser's cache, if available.
Public methodStatic memberReload(IBrowser, Boolean)
Reloads the page being displayed, optionally ignoring the cache (which means the whole page including all .css, .js etc. resources will be re-fetched).
Public methodStatic memberReload(IChromiumWebBrowserBase, Boolean)
Reloads the page being displayed, optionally ignoring the cache (which means the whole page including all .css, .js etc. resources will be re-fetched).
Public methodStatic memberReplaceMisspelling(IBrowser, String)
If a misspelled word is currently selected in an editable node calling this method will replace it with the specified word.
Public methodStatic memberReplaceMisspelling(IChromiumWebBrowserBase, String)
If a misspelled word is currently selected in an editable node calling this method will replace it with the specified word.
Public methodStatic memberSelectAll(IBrowser)
Execute SelectAll on the focused frame.
Public methodStatic memberSelectAll(IChromiumWebBrowserBase)
Execute SelectAll on the focused frame.
Public methodStatic memberSendMouseClickEvent
Send a mouse click event to the browser.
Public methodStatic memberSendMouseMoveEvent
Send a mouse move event to the browser.
Public methodStatic memberSendMouseWheelEvent(IBrowser, Int32, Int32, Int32, Int32, CefEventFlags)
Send a mouse wheel event to the browser.
Public methodStatic memberSendMouseWheelEvent(IBrowserHost, Int32, Int32, Int32, Int32, CefEventFlags)
Send a mouse wheel event to the browser.
Public methodStatic memberSendMouseWheelEvent(IChromiumWebBrowserBase, Int32, Int32, Int32, Int32, CefEventFlags)
Send a mouse wheel event to the browser.
Public methodStatic memberSetAsPopup
Public methodStatic memberSetZoomLevel(IBrowser, Double)
Change the ZoomLevel to the specified value. Can be set to 0.0 to clear the zoom level.
Public methodStatic memberSetZoomLevel(IChromiumWebBrowserBase, Double)
Change the ZoomLevel to the specified value. Can be set to 0.0 to clear the zoom level.
Public methodStatic memberShowDevTools(IBrowser, IWindowInfo, Int32, Int32)
Open developer tools in its own window.
Public methodStatic memberShowDevTools(IChromiumWebBrowserBase, IWindowInfo, Int32, Int32)
Open developer tools in its own window.
Public methodStatic memberStartDownload(IBrowser, String)
Download the file at url using IDownloadHandler.
Public methodStatic memberStartDownload(IChromiumWebBrowserBase, String)
Download the file at url using IDownloadHandler.
Public methodStatic memberStop(IBrowser)
Stops loading the current page.
Public methodStatic memberStop(IChromiumWebBrowserBase)
Stops loading the current page.
Public methodStatic memberStopFinding(IBrowser, Boolean)
Cancel all searches that are currently going on.
Public methodStatic memberStopFinding(IChromiumWebBrowserBase, Boolean)
Cancel all searches that are currently going on.
Public methodStatic memberThrowExceptionIfBrowserHostNull
Throw exception if browser host null.
Public methodStatic memberUndo(IBrowser)
Execute Undo on the focused frame.
Public methodStatic memberUndo(IChromiumWebBrowserBase)
Execute Undo on the focused frame.
Public methodStatic memberUnRegisterResourceHandler
Unregister a ResourceHandler. Can only be used when browser.ResourceHandlerFactory is an instance of DefaultResourceHandlerFactory.
Public methodStatic memberViewSource(IBrowser)
Opens up a new program window (using the default text editor) where the source code of the currently displayed web page is shown.
Public methodStatic memberViewSource(IChromiumWebBrowserBase)
Opens up a new program window (using the default text editor) where the source code of the currently displayed web page is shown.
Public methodStatic memberCode exampleWaitForNavigationAsync
This resolves when the browser navigates to a new URL or reloads. It is useful for when you run code which will indirectly cause the browser to navigate. A common use case would be when executing javascript that results in a navigation. e.g. clicks a link This must be called before executing the action that navigates the browser. It may not resolve correctly if called after.
Public methodStatic memberCode exampleWaitForSelectorAsync
Waits for a DOM element specified by the selector string to be added to or removed from the DOM. A simplified version of Puppeteer WaitForSelector. Uses a MutationObserver to wait for the element to become added or removed.
Top
Fields
See Also