C# Class CefSharp.WebBrowserExtensions

Afficher le fichier Open project: cefsharp/CefSharp Class Usage Examples

Méthodes publiques

Méthode 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

Méthode 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 méthode

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.
Résultat void

Back() public static méthode

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

CloseDevTools() public static méthode

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
Résultat void

Copy() public static méthode

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

Cut() public static méthode

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

Delete() public static méthode

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

EvaluateScriptAsync() public static méthode

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
Résultat Task

EvaluateScriptAsync() public static méthode

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
Résultat Task

EvaluateScriptAsync() public static méthode

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

ExecuteScriptAsync() public static méthode

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
Résultat void

Find() public static méthode

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.
Résultat void

Forward() public static méthode

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

GetFocusedFrame() public static méthode

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

GetMainFrame() public static méthode

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

GetSourceAsync() public static méthode

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
Résultat Task

GetTextAsync() public static méthode

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
Résultat Task

GetZoomLevelAsync() public static méthode

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

LoadHtml() public static méthode

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.
Résultat void

LoadHtml() public static méthode

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
Résultat void

LoadString() public static méthode

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
Résultat void

Paste() public static méthode

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

Print() public static méthode

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
Résultat void

PrintToPdfAsync() public static méthode

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.
Résultat Task

Redo() public static méthode

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

RegisterResourceHandler() public static méthode

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
Résultat void

Reload() public static méthode

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
Résultat void

Reload() public static méthode

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.
Résultat void

ReplaceMisspelling() public static méthode

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.
Résultat void

SelectAll() public static méthode

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

SendMouseWheelEvent() public static méthode

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
Résultat void

SetAsPopup() public static méthode

public static SetAsPopup ( this browser ) : void
browser this
Résultat void

SetZoomLevel() public static méthode

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
Résultat void

ShowDevTools() public static méthode

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

Stop() public static méthode

Stops loading the current page.
public static Stop ( this browser ) : void
browser this
Résultat void

StopFinding() public static méthode

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
Résultat void

ThrowExceptionIfBrowserNotInitialized() public static méthode

public static ThrowExceptionIfBrowserNotInitialized ( this browser ) : void
browser this
Résultat void

UnRegisterResourceHandler() public static méthode

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
Résultat void

Undo() public static méthode

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

ViewSource() public static méthode

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
Résultat void