Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Configuration

mattkol edited this page Mar 29, 2018 · 39 revisions

Most required Cef configuration is done via ChromelyConfiguration class. ChromelyConfiguration provides default values that can be used as-is or set new properties.

The followings are configured:

AppArgs  - Cef app arguments
StartUrl - Cef start url
HostWidth - Cef start width
HostHeight -  Cef start height
LogSeverity - Cef log severity
LogFile - Cef log file
PerformDependencyCheck - Cef dependency check flag
Locale - Cef locale

Use default logger or set a new one
Use default IOC container or set a new one
Use of default resource scheme handler
Use of default url/http scheme handler
Use of default JS handler (CefSharp only)
Add/register custom command line arguments
Add/register custom setting properties
Registration of custom url/http schemes
Registration of external url schemes
Registration of custom scheme handlers
Registration of custom Javascript objects
Register custom message router handlers (CefGlue)

ChromelyConfiguration is fluently set. Sample Configuration:

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .WithAppArgs(args)
                              .WithHostSize(1200, 900)
                              .WithLogFile("logs\\chromely.cef_new.log")
                              .WithStartUrl(startUrl)
                              .WithLogSeverity(LogSeverity.Info)
                              .UseDefaultLogger("logs\\chromely_new.log", true)
                              .RegisterSchemeHandler("http", "chromely.com", new CefGlueSchemeHandlerFactory());

How to add additional CEF3 command line arguments

Both CefSharp and CefGlue will be launched with common command line arguments. Extra arguments can be added.

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                              .WithCommandLineArg("no-sandbox", "1")
                              .WithCommandLineArg("device-scale-factor", "1")
                              ....

How to add custom settings

Both CefSharp and CefGlue will be launched with common setting properties. This can be overwritten by creating custom settings.

This will require setting:

  • Key - that can be found at - CefSettingKeys.
  • The value to be set. It can be actual value [bool, int, string], or string that is "parsable" to actual value.
ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                              .WithCustomSetting(CefSettingKeys.BrowserSubprocessPath, full_path_to_subprocess)
                              .WithCustomSetting(CefSettingKeys.SingleProcess, true)
                              ....

How to add custom handlers

Both CefSharp and CefGlue come with few default handlers like CefSharpContextMenuHandler for CefSharp, CefGlueContextMenuHandler for CefGllue. These handlers can be replaced with custom handlers and new one can be added. This is done via registering custom handling using RegisterCustomHandler.

This will require setting:

  • Key - that can be found at - CefHandlerKey.
  • The value to be set. This has to be valid handler class. It MUST inherit from CefSharp, CefGlue provided handler base classes or interfaces.
ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                             .RegisterCustomHandler(CefHandlerKey.LifeSpanHandler, typeof(CustomLifeSpanHandler))
                             .RegisterCustomHandler(CefHandlerKey.LoadHandler, typeof(CustomLoadHandler))
                             .RegisterCustomHandler(CefHandlerKey.RequestHandler, typeof(CustomRequestHandler))
                             .RegisterCustomHandler(CefHandlerKey.DisplayHandler, typeof(CustomDisplayHandler))
                             .RegisterCustomHandler(CefHandlerKey.ContextMenuHandler, typeof(CustomContextMenuHandler));
                              ....

How to set new logger (or use default)

Chromely provides a simple default logger. This can be set in the configuration. The default file can be changed and also if the logs can also be written to the console.

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                              .UseDefaultLogger("logs\\chromely_new.log", true)
                              ....

A new logger (of type IChromelyLogger) can be set.

IChromelyLogger logger = new NewLogger();
ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                               ....
                              .WithLogger(logger)
                              ....

How to set new IOC Container

A new IOC container (of type IChromelyContainer) can be set prior to setting the configuration object or set passing via constructor (create). *** This must be done prior to other registrations otherwise the default container will kick in during these registrations and will be lost (invalid). ONLY one IOC container is required.

// The IOC container must implement the IChromelyContainer interface.
IChromelyContainer newContainer = new CustomContainer();
IoC.Container = newContainer;

Or:

// The IOC container must implement the IChromelyContainer interface.
IChromelyContainer newContainer = new CustomContainer();
ChromelyConfiguration config = ChromelyConfiguration()
                              .Create(newContainer)
                              .....

How to register custom url schemes

Custom url schemes can be just custom (can be used as developer pleases) or custom external urls. External urls are urls opened by the default browser - externally to Chromely (e.g - www.google.com). For more on external url registration see - External Url Registration. One or more custom url schemes can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterCustomrUrlScheme("http", "chromely.com")
                              .RegisterCustomrUrlScheme("test", "test.com")
                              .RegisterExternaleUrlScheme("https", "google.com")
                              .RegisterExternaleUrlScheme("https", "https://github.com/mattkol/Chromely")
                              .....

How to register custom scheme handlers

For more on custom scheme handling registration see - Custom Scheme Handling.

One or more custom scheme handlers can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterSchemeHandler("http", "chromely.com", new CefGlueSchemeHandlerFactory())
                              .RegisterSchemeHandler("http", "chromely2.com", new CustomSchemeHandlerFactory())
                              .....

How to register custom Javascript objects (Only CefSharp apps)

For more on custom Javascript objects registration see - Custom Javascript Object.

One or more custom Javascript objects can be registered with:

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterJsHandler("boundControllerAsync", new CefSharpBoundObject(), null, true);
                              .RegisterJsHandler("boundControllerAsync2", new NewCefSharpBoundObject(), null, true);
                              .....

How to register generic message router handlers (Only CefGlue apps)

For more on generic message router handlers registration see - Generic Message Routing.

One or more generic message router handlers can be registered with:

**** If no object is registered, the default Handler can always be used.

ChromelyConfiguration config = ChromelyConfiguration()
                              .Create()
                              ....
                              .RegisterMessageRouterHandler(new NewMessageRouter());
                              .RegisterMessageRouterHandler(new NewMessageRouter2());
                              .....