C# Class CefSharp.WebBrowserExtensions

ファイルを表示 Open project: cefsharp/CefSharp Class Usage Examples

Public Methods

Method Description
AddWordToDictionary ( this cefBrowser, string word ) : void

Add the specified word to the spelling dictionary.

Back ( this browser ) : void

Navigates back, must check IWebBrowser.CanGoBack before calling this method.

CloseDevTools ( this cefBrowser ) : void

Explicitly close the developer tools window if one exists for this browser instance.

Copy ( this browser ) : void

Execute Copy on the focused frame

Cut ( this browser ) : void

Execute Cut on the focused frame

Delete ( this browser ) : void

Execute Delete on the focused frame

EvaluateScriptAsync ( this browser, System.TimeSpan timeout, string methodName ) : Task

Evaluate some 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)

EvaluateScriptAsync ( this browser, string methodName ) : Task

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)

EvaluateScriptAsync ( this browser, string script, System.TimeSpan timeout = null ) : Task
ExecuteScriptAsync ( this browser, string methodName ) : void

Execute some 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)

Find ( this cefBrowser, int identifier, string searchText, bool forward, bool matchCase, bool findNext ) : void

Search for text within the current page.

Forward ( this browser ) : void

Navigates forward, must check IWebBrowser.CanGoForward before calling this method.

GetFocusedFrame ( this webBrowser ) : IFrame

Returns the focused frame for the browser window.

GetMainFrame ( this webBrowser ) : IFrame

Returns the main (top-level) frame for the browser window.

GetSourceAsync ( this browser ) : Task

Retrieve the main frame's HTML source using a Task{String}.

GetTextAsync ( this browser ) : Task

Retrieve the main frame's display text using a Task{String}.

GetZoomLevelAsync ( this cefBrowser ) : Task

Asynchronously gets the current Zoom Level.

LoadHtml ( this browser, string html, string url ) : void

Registers and loads a ResourceHandler that represents the HTML content.

`Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps the provided HTML in a ResourceHandler and loads the provided url using the IWebBrowser.Load method. Defaults to using Encoding.UTF8 for character encoding The url must start with a valid schema, other uri's such as about:blank are invalid A valid example looks like http://test/page

LoadHtml ( this browser, string html, string url, Encoding encoding ) : void

Registers and loads a ResourceHandler that represents the HTML content.

`Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps the provided HTML in a ResourceHandler and loads the provided url using the IWebBrowser.Load method.

LoadString ( this browser, string html, string url ) : void

Load the string contents with the specified dummy url. Web security restrictions may not behave as expected.

Paste ( this browser ) : void

Execute Paste on the focused frame

Print ( this cefBrowser ) : void

Opens a Print Dialog which if used (can be user cancelled) will print the browser contents.

PrintToPdfAsync ( this cefBrowser, string path, CefSharp.PdfPrintSettings settings = null ) : Task

Asynchronously prints the current browser contents to the PDF file specified. The caller is responsible for deleting the file when done.

Redo ( this browser ) : void

Execute Redo on the focused frame

RegisterResourceHandler ( this browser, string url, Stream stream, string mimeType = ResourceHandler.DefaultMimeType ) : void

Register a ResourceHandler. Can only be used when browser.ResourceHandlerFactory is an instance of DefaultResourceHandlerFactory

Reload ( this browser ) : void

Reloads the page being displayed. This method will use data from the browser's cache, if available.

Reload ( this browser, bool ignoreCache ) : void

Reloads the page being displayed, optionally ignoring the cache (which means the whole page including all .css, .js etc. resources will be re-fetched).

ReplaceMisspelling ( this cefBrowser, string word ) : void

If a misspelled word is currently selected in an editable node calling this method will replace it with the specified word.

SelectAll ( this browser ) : void

Execute SelectAll on the focused frame

SendMouseWheelEvent ( this browser, int x, int y, int deltaX, int deltaY, CefEventFlags modifiers ) : void
SetAsPopup ( this browser ) : void
SetZoomLevel ( this cefBrowser, double zoomLevel ) : void

Change the ZoomLevel to the specified value. Can be set to 0.0 to clear the zoom level.

If called on the CEF UI thread the change will be applied immediately. Otherwise, the change will be applied asynchronously on the CEF UI thread. The CEF UI thread is different to the WPF/WinForms UI Thread

ShowDevTools ( this cefBrowser ) : void

Open developer tools in its own window.

Stop ( this browser ) : void

Stops loading the current page.

StopFinding ( this cefBrowser, bool clearSelection ) : void

Cancel all searches that are currently going on.

ThrowExceptionIfBrowserNotInitialized ( this browser ) : void
UnRegisterResourceHandler ( this browser, string url ) : void

Unregister a ResourceHandler. Can only be used when browser.ResourceHandlerFactory is an instance of DefaultResourceHandlerFactory

Undo ( this browser ) : void

Execute Undo on the focused frame

ViewSource ( this browser ) : void

Opens up a new program window (using the default text editor) where the source code of the currently displayed web page is shown.

Private Methods

Method Description
GetScript ( string methodName, object args ) : string

Transforms the methodName and arguments into valid Javascript code. Will encapsulate params in single quotes (unless int, uint, etc)

ThrowExceptionIfBrowserHostNull ( IBrowserHost browserHost ) : void
ThrowExceptionIfBrowserNull ( IBrowser browser ) : void
ThrowExceptionIfFrameNull ( IFrame frame ) : void

Method Details

AddWordToDictionary() public static method

Add the specified word to the spelling dictionary.
public static AddWordToDictionary ( this cefBrowser, string word ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
word string The new word that will be added to the dictionary.
return void

Back() public static method

Navigates back, must check IWebBrowser.CanGoBack before calling this method.
public static Back ( this browser ) : void
browser this
return void

CloseDevTools() public static method

Explicitly close the developer tools window if one exists for this browser instance.
public static CloseDevTools ( this cefBrowser ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
return void

Copy() public static method

Execute Copy on the focused frame
public static Copy ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

Cut() public static method

Execute Cut on the focused frame
public static Cut ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

Delete() public static method

Execute Delete on the focused frame
public static Delete ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

EvaluateScriptAsync() public static method

Evaluate some 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 static EvaluateScriptAsync ( this browser, System.TimeSpan timeout, string methodName ) : Task
browser this The ChromiumWebBrowser instance this method extends
timeout System.TimeSpan The timeout after which the Javascript code execution should be aborted.
methodName string The javascript method name to execute
return Task

EvaluateScriptAsync() public static method

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 static EvaluateScriptAsync ( this browser, string methodName ) : Task
browser this The ChromiumWebBrowser instance this method extends
methodName string The javascript method name to execute
return Task

EvaluateScriptAsync() public static method

public static EvaluateScriptAsync ( this browser, string script, System.TimeSpan timeout = null ) : Task
browser this
script string
timeout System.TimeSpan
return Task

ExecuteScriptAsync() public static method

Execute some 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 static ExecuteScriptAsync ( this browser, string methodName ) : void
browser this The ChromiumWebBrowser instance this method extends
methodName string The javascript method name to execute
return void

Find() public static method

Search for text within the current page.
public static Find ( this cefBrowser, int identifier, string searchText, bool forward, bool matchCase, bool findNext ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
identifier int Can be used in can conjunction with searchText to have multiple /// searches running simultaneously.
searchText string search text
forward bool indicates whether to search forward or backward within the page.
matchCase bool indicates whether the search should be case-sensitive.
findNext bool indicates whether this is the first request or a follow-up.
return void

Forward() public static method

Navigates forward, must check IWebBrowser.CanGoForward before calling this method.
public static Forward ( this browser ) : void
browser this
return void

GetFocusedFrame() public static method

Returns the focused frame for the browser window.
public static GetFocusedFrame ( this webBrowser ) : IFrame
webBrowser this
return IFrame

GetMainFrame() public static method

Returns the main (top-level) frame for the browser window.
public static GetMainFrame ( this webBrowser ) : IFrame
webBrowser this
return IFrame

GetSourceAsync() public static method

Retrieve the main frame's HTML source using a Task{String}.
public static GetSourceAsync ( this browser ) : Task
browser this The ChromiumWebBrowser instance this method extends
return Task

GetTextAsync() public static method

Retrieve the main frame's display text using a Task{String}.
public static GetTextAsync ( this browser ) : Task
browser this The ChromiumWebBrowser instance this method extends
return Task

GetZoomLevelAsync() public static method

Asynchronously gets the current Zoom Level.
public static GetZoomLevelAsync ( this cefBrowser ) : Task
cefBrowser this
return Task

LoadHtml() public static method

Registers and loads a ResourceHandler that represents the HTML content.
`Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps the provided HTML in a ResourceHandler and loads the provided url using the IWebBrowser.Load method. Defaults to using Encoding.UTF8 for character encoding The url must start with a valid schema, other uri's such as about:blank are invalid A valid example looks like http://test/page
public static LoadHtml ( this browser, string html, string url ) : void
browser this The ChromiumWebBrowser instance this method extends
html string The HTML content.
url string The URL that will be treated as the address of the content.
return void

LoadHtml() public static method

Registers and loads a ResourceHandler that represents the HTML content.
`Cef` Native `LoadHtml` is unpredictable and only works sometimes, this method wraps the provided HTML in a ResourceHandler and loads the provided url using the IWebBrowser.Load method.
public static LoadHtml ( this browser, string html, string url, Encoding encoding ) : void
browser this The ChromiumWebBrowser instance this method extends
html string The HTML content.
url string The URL that will be treated as the address of the content.
encoding System.Text.Encoding Character Encoding
return void

LoadString() public static method

Load the string contents with the specified dummy url. Web security restrictions may not behave as expected.
public static LoadString ( this browser, string html, string url ) : void
browser this The ChromiumWebBrowser instance this method extends
html string html string to load
url string the url should have a standard scheme (for example, http scheme) or behaviors like link clicks
return void

Paste() public static method

Execute Paste on the focused frame
public static Paste ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

Print() public static method

Opens a Print Dialog which if used (can be user cancelled) will print the browser contents.
public static Print ( this cefBrowser ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
return void

PrintToPdfAsync() public static method

Asynchronously prints the current browser contents to the PDF file specified. The caller is responsible for deleting the file when done.
public static PrintToPdfAsync ( this cefBrowser, string path, CefSharp.PdfPrintSettings settings = null ) : Task
cefBrowser this The object this method extends.
path string Output file location.
settings CefSharp.PdfPrintSettings Print Settings.
return Task

Redo() public static method

Execute Redo on the focused frame
public static Redo ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

RegisterResourceHandler() public static method

Register a ResourceHandler. Can only be used when browser.ResourceHandlerFactory is an instance of DefaultResourceHandlerFactory
public static RegisterResourceHandler ( this browser, string url, Stream stream, string mimeType = ResourceHandler.DefaultMimeType ) : void
browser this The ChromiumWebBrowser instance this method extends
url string the url of the resource to unregister
stream Stream Stream to be registered, the stream should not be shared with any other instances of DefaultResourceHandlerFactory
mimeType string the mimeType
return void

Reload() public static method

Reloads the page being displayed. This method will use data from the browser's cache, if available.
public static Reload ( this browser ) : void
browser this
return void

Reload() public static method

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 static Reload ( this browser, bool ignoreCache ) : void
browser this The ChromiumWebBrowser instance this method extends
ignoreCache bool true A reload is performed ignoring browser cache; false A reload is /// performed using files from the browser cache, if available.
return void

ReplaceMisspelling() public static method

If a misspelled word is currently selected in an editable node calling this method will replace it with the specified word.
public static ReplaceMisspelling ( this cefBrowser, string word ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
word string The new word that will replace the currently selected word.
return void

SelectAll() public static method

Execute SelectAll on the focused frame
public static SelectAll ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

SendMouseWheelEvent() public static method

public static SendMouseWheelEvent ( this browser, int x, int y, int deltaX, int deltaY, CefEventFlags modifiers ) : void
browser this
x int
y int
deltaX int
deltaY int
modifiers CefEventFlags
return void

SetAsPopup() public static method

public static SetAsPopup ( this browser ) : void
browser this
return void

SetZoomLevel() public static method

Change the ZoomLevel to the specified value. Can be set to 0.0 to clear the zoom level.
If called on the CEF UI thread the change will be applied immediately. Otherwise, the change will be applied asynchronously on the CEF UI thread. The CEF UI thread is different to the WPF/WinForms UI Thread
public static SetZoomLevel ( this cefBrowser, double zoomLevel ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
zoomLevel double zoom level
return void

ShowDevTools() public static method

Open developer tools in its own window.
public static ShowDevTools ( this cefBrowser ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
return void

Stop() public static method

Stops loading the current page.
public static Stop ( this browser ) : void
browser this
return void

StopFinding() public static method

Cancel all searches that are currently going on.
public static StopFinding ( this cefBrowser, bool clearSelection ) : void
cefBrowser this The ChromiumWebBrowser instance this method extends
clearSelection bool clear the current search selection
return void

ThrowExceptionIfBrowserNotInitialized() public static method

public static ThrowExceptionIfBrowserNotInitialized ( this browser ) : void
browser this
return void

UnRegisterResourceHandler() public static method

Unregister a ResourceHandler. Can only be used when browser.ResourceHandlerFactory is an instance of DefaultResourceHandlerFactory
public static UnRegisterResourceHandler ( this browser, string url ) : void
browser this The ChromiumWebBrowser instance this method extends
url string the url of the resource to unregister
return void

Undo() public static method

Execute Undo on the focused frame
public static Undo ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void

ViewSource() public static method

Opens up a new program window (using the default text editor) where the source code of the currently displayed web page is shown.
public static ViewSource ( this browser ) : void
browser this The ChromiumWebBrowser instance this method extends
return void