Skip to main content

Plugin Configuration

CefPlugin is the single entry point for adding bevy_cef to your application. It accepts three configuration fields and composes all internal sub-plugins automatically.

CefPlugin Fields

pub struct CefPlugin {
pub command_line_config: CommandLineConfig,
pub extensions: CefExtensions,
pub root_cache_path: Option<String>,
}

command_line_config

CommandLineConfig controls the command-line arguments passed to CEF during initialization. CEF supports a wide range of switches that affect rendering, security, and debugging behavior.

use bevy_cef::prelude::*;

let plugin = CefPlugin {
command_line_config: CommandLineConfig::new()
.arg("--disable-gpu")
.arg("--remote-debugging-port=9222"),
..default()
};

Use this to pass CEF-specific flags such as --disable-gpu, --remote-debugging-port, or --enable-media-stream. Refer to the CEF command-line flags documentation for available options.

extensions

CefExtensions registers custom JavaScript extensions that are available globally to all webviews. Extensions are JavaScript code that runs in the V8 context of the render process, making them available before any page scripts execute.

use bevy_cef::prelude::*;

let mut extensions = CefExtensions::default();
extensions.register_extension(
"my_extension",
r#"
var myGlobal = {
version: '1.0.0',
greet: function(name) { return 'Hello, ' + name; }
};
"#,
);

let plugin = CefPlugin {
extensions,
..default()
};

Unlike PreloadScripts (which are per-webview and run after the page's context is created), extensions are registered once at the CEF level and are available in every webview. They run in V8's extension context, which means they execute before any page scripts and cannot access the DOM directly.

root_cache_path

root_cache_path sets the root directory where CEF stores its cache data (cookies, localStorage, IndexedDB, and other persistent browser state).

let plugin = CefPlugin {
root_cache_path: Some("/path/to/cache".to_string()),
..default()
};

When set to None (the default), CEF uses an in-memory cache that is discarded when the application exits. Set this to a directory path if you need persistent browser state across application sessions.

Default Configuration

For most use cases, the default configuration is sufficient:

app.add_plugins((DefaultPlugins, CefPlugin::default()));

This initializes CEF with no custom command-line arguments, no extensions, and an in-memory cache.

Sub-Plugin Tree

CefPlugin internally adds the following sub-plugins. You do not add these individually -- they are included automatically:

Sub-PluginPurpose
LocalHostPluginRegisters the cef://localhost/ scheme for serving local assets from Bevy's asset system.
MessageLoopPluginInitializes CEF and calls cef_do_message_loop_work() once per frame.
WebviewCoreComponentsPluginRegisters core webview components (WebviewSource, WebviewSize, etc.) with Bevy.
WebviewPlugin / MeshWebviewPluginManages webview lifecycle: creation, texture delivery, material assignment, and DevTools.
IpcPluginComposes IpcRawEventPlugin and HostEmitPlugin for bidirectional IPC.
KeyboardPluginForwards keyboard events from Bevy to CEF.
SystemCursorIconPluginUpdates the system cursor icon based on the webview's CSS cursor property.
NavigationPluginRegisters observers for RequestGoBack and RequestGoForward events.
ZoomPluginWatches for ZoomLevel changes and forwards them to CEF.
AudioMutePluginWatches for AudioMuted changes and forwards them to CEF.
RemotePluginAdds Bevy's RemotePlugin if not already present, enabling BRP communication.