C# Class CefSharp.OffScreen.ChromiumWebBrowser

An offscreen instance of Chromium that you can use to take snapshots or evaluate JavaScript.
Inheritance: IRenderWebBrowser
Show file Open project: cefsharp/CefSharp Class Usage Examples

Public Properties

Property Type Description
BitmapLock object

Private Properties

Property Type Description
IRenderWebBrowser CefSharp.Internals.BitmapInfo
IRenderWebBrowser CefSharp.Internals.ScreenInfo
IRenderWebBrowser CefSharp.Internals.ViewRect
IRenderWebBrowser bool
IRenderWebBrowser void
IRenderWebBrowser void
IRenderWebBrowser void
IRenderWebBrowser void
IRenderWebBrowser void
IRenderWebBrowser void
IWebBrowser bool
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
IWebBrowserInternal void
MergeBitmaps System.Drawing.Bitmap

Public Methods

Method Description
ChromiumWebBrowser ( string address = "", BrowserSettings browserSettings = null, RequestContext requestContext = null, bool automaticallyCreateBrowser = true ) : System

Create a new OffScreen Chromium Browser

CreateBrowser ( IntPtr windowHandle ) : void

Create the underlying browser. The instance address, browser settings and request context will be used.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetBrowser ( ) : IBrowser

Returns the current CEF Browser Instance

InvokeRenderAsync ( CefSharp.Internals.BitmapInfo bitmapInfo ) : void

Invoked from CefRenderHandler.OnPaint A new Bitmap is only created when BitmapInfo.CreateNewBitmap is true, otherwise the new buffer is simply copied into the backBuffer of the existing Bitmap for efficiency. Locking provided by OnPaint as this method is called in it's lock scope.

Load ( string url ) : void

Loads the specified URL.

RegisterAsyncJsObject ( string name, object objectToBind, BindingOptions options = null ) : void

Asynchronously registers a Javascript object in this specific browser instance.

Only methods of the object will be availabe.

The registered methods can only be called in an async way, they will all return immeditaly and the resulting object will be a standard javascript Promise object which is usable to wait for completion or failure.

RegisterJsObject ( string name, object objectToBind, BindingOptions options = null ) : void

Registers a Javascript object in this specific browser instance.

ScreenshotAsync ( bool ignoreExistingScreenshot = false, PopupBlending blend = PopupBlending.Main ) : Task

Starts a task that waits for the next rendering from Chrome. Chrome also renders the page loading, so if you want to see a complete rendering, only start this task once your page is loaded (which you can detect via FrameLoadEnd or your own heuristics based on evaluating JavaScript). It is your responsibility to dispose the returned Bitmap. The bitmap size is determined by the Size property set earlier.

ScreenshotOrNull ( PopupBlending blend = PopupBlending.Main ) : Bitmap

Immediately returns a copy of the last rendering from Chrome, or null if no rendering has occurred yet. Chrome also renders the page loading, so if you want to see a complete rendering, only start this task once your page is loaded (which you can detect via FrameLoadEnd or your own heuristics based on evaluating JavaScript). It is your responsibility to dispose the returned Bitmap. The bitmap size is determined by the Size property set earlier.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Releases unmanaged and - optionally - managed resources.

SetBitmap ( Bitmap bitmap ) : void

Sets the Bitmap to render with a copy of bitmap in parameter.

Private Methods

Method Description
IRenderWebBrowser ( bool isPopup ) : CefSharp.Internals.BitmapInfo

Creates the bitmap information.

IRenderWebBrowser ( ) : CefSharp.Internals.ScreenInfo

Gets the screen information.

IRenderWebBrowser ( ) : CefSharp.Internals.ViewRect

Gets the view rect.

IRenderWebBrowser ( IDragData dragData, DragOperationsMask mask, int x, int y ) : bool

Starts the dragging.

IRenderWebBrowser ( CefSharp.Internals.BitmapInfo bitmapInfo ) : void

Invoked from CefRenderHandler.OnPaint A new Bitmap is only created when BitmapInfo.CreateNewBitmap is true, otherwise the new buffer is simply copied into the backBuffer of the existing Bitmap for efficiency. Locking provided by OnPaint as this method is called in it's lock scope.

IRenderWebBrowser ( DragOperationsMask operation ) : void
IRenderWebBrowser ( IntPtr handle, CefCursorType type ) : void

Sets the cursor.

IRenderWebBrowser ( Range selectedRange, System.Drawing.Rect characterBounds ) : void
IRenderWebBrowser ( bool show ) : void

Sets the popup is open.

IRenderWebBrowser ( int width, int height, int x, int y ) : void

Sets the popup size and position.

IWebBrowser ( ) : bool

Has Focus - Always False

IWebBrowserInternal ( AddressChangedEventArgs args ) : void

Sets the address.

IWebBrowserInternal ( ConsoleMessageEventArgs args ) : void

Handles the E:ConsoleMessage event.

IWebBrowserInternal ( FrameLoadEndEventArgs args ) : void

Handles the E:FrameLoadEnd event.

IWebBrowserInternal ( FrameLoadStartEventArgs args ) : void

Handles the E:FrameLoadStart event.

IWebBrowserInternal ( IBrowser browser ) : void

Called when [after browser created].

IWebBrowserInternal ( LoadErrorEventArgs args ) : void

Handles the E:LoadError event.

IWebBrowserInternal ( LoadingStateChangedEventArgs args ) : void

Sets the loading state change.

IWebBrowserInternal ( StatusMessageEventArgs args ) : void

Handles the E:StatusMessage event.

IWebBrowserInternal ( TitleChangedEventArgs args ) : void

Sets the title.

IWebBrowserInternal ( string tooltipText ) : void

Sets the tooltip text.

MergeBitmaps ( Bitmap firstBitmap, Bitmap secondBitmap ) : Bitmap

Creates a new bitmap with the dimensions of firstBitmap, then draws the firstBitmap, then overlays the secondBitmap

Method Details

ChromiumWebBrowser() public method

Create a new OffScreen Chromium Browser
Cef::Initialize() failed
public ChromiumWebBrowser ( string address = "", BrowserSettings browserSettings = null, RequestContext requestContext = null, bool automaticallyCreateBrowser = true ) : System
address string Initial address (url) to load
browserSettings BrowserSettings The browser settings to use. If null, the default settings are used.
requestContext RequestContext See for more details. Defaults to null
automaticallyCreateBrowser bool automatically create the underlying Browser
return System

CreateBrowser() public method

Create the underlying browser. The instance address, browser settings and request context will be used.
An instance of the underlying offscreen browser has already been created, this method can only be called once.
public CreateBrowser ( IntPtr windowHandle ) : void
windowHandle System.IntPtr Window handle if any, IntPtr.Zero is the default
return void

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public Dispose ( ) : void
return void

Dispose() protected method

Releases unmanaged and - optionally - managed resources.
protected Dispose ( bool disposing ) : void
disposing bool true to release both managed and unmanaged resources; false to release only unmanaged resources.
return void

GetBrowser() public method

Returns the current CEF Browser Instance
public GetBrowser ( ) : IBrowser
return IBrowser

InvokeRenderAsync() public method

Invoked from CefRenderHandler.OnPaint A new Bitmap is only created when BitmapInfo.CreateNewBitmap is true, otherwise the new buffer is simply copied into the backBuffer of the existing Bitmap for efficiency. Locking provided by OnPaint as this method is called in it's lock scope.
public InvokeRenderAsync ( CefSharp.Internals.BitmapInfo bitmapInfo ) : void
bitmapInfo CefSharp.Internals.BitmapInfo information about the bitmap to be rendered
return void

Load() public method

Loads the specified URL.
public Load ( string url ) : void
url string The URL to be loaded.
return void

RegisterAsyncJsObject() public method

Asynchronously registers a Javascript object in this specific browser instance.

Only methods of the object will be availabe.

The registered methods can only be called in an async way, they will all return immeditaly and the resulting object will be a standard javascript Promise object which is usable to wait for completion or failure.
Browser is already initialized. RegisterJsObject must be + /// called before the underlying CEF browser is created.
public RegisterAsyncJsObject ( string name, object objectToBind, BindingOptions options = null ) : void
name string The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).
objectToBind object The object to be made accessible to Javascript.
options BindingOptions binding options - camelCaseJavascriptNames default to true
return void

RegisterJsObject() public method

Registers a Javascript object in this specific browser instance.
Browser is already initialized. RegisterJsObject must be + /// called before the underlying CEF browser is created.
public RegisterJsObject ( string name, object objectToBind, BindingOptions options = null ) : void
name string The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).
objectToBind object The object to be made accessible to Javascript.
options BindingOptions binding options - camelCaseJavascriptNames default to true
return void

ScreenshotAsync() public method

Starts a task that waits for the next rendering from Chrome. Chrome also renders the page loading, so if you want to see a complete rendering, only start this task once your page is loaded (which you can detect via FrameLoadEnd or your own heuristics based on evaluating JavaScript). It is your responsibility to dispose the returned Bitmap. The bitmap size is determined by the Size property set earlier.
public ScreenshotAsync ( bool ignoreExistingScreenshot = false, PopupBlending blend = PopupBlending.Main ) : Task
ignoreExistingScreenshot bool Ignore existing bitmap (if any) and return the next avaliable bitmap
blend PopupBlending Choose which bitmap to retrieve, choose for a merged bitmap.
return Task

ScreenshotOrNull() public method

Immediately returns a copy of the last rendering from Chrome, or null if no rendering has occurred yet. Chrome also renders the page loading, so if you want to see a complete rendering, only start this task once your page is loaded (which you can detect via FrameLoadEnd or your own heuristics based on evaluating JavaScript). It is your responsibility to dispose the returned Bitmap. The bitmap size is determined by the Size property set earlier.
public ScreenshotOrNull ( PopupBlending blend = PopupBlending.Main ) : Bitmap
blend PopupBlending Choose which bitmap to retrieve, choose for a merged bitmap.
return System.Drawing.Bitmap

SetBitmap() protected method

Sets the Bitmap to render with a copy of bitmap in parameter.
protected SetBitmap ( Bitmap bitmap ) : void
bitmap System.Drawing.Bitmap The bitmap which will be copied
return void

Property Details

BitmapLock public property

Need a lock because the caller may be asking for the bitmap while Chromium async rendering has returned on another thread.
public object BitmapLock
return object