feat: add custom CEF V8 extensions support (#17)

* feat: Register extensions in render process

- Add CefExtensions type to hold V8 extension code
- Pass extensions through BrowserProcessAppBuilder
- Register extensions in RenderProcessHandler on WebKit initialization
- Decode JSON extensions from command line switch
- Prefix extension names with "v8/" per CEF convention
- Include actual JSON in error messages for debugging

l

* feat: refactor window.cef API and register as CEF extension

* fix: remove debug print statements in render process handler

* refactor: centralize EXTENSIONS_SWITCH constant in util.rs

* fmt

* refactor: implement Default trait for CefApiHandler

* docs: add documentation for CefApiHandler and its JavaScript API functions

---------

Co-authored-by: not-elm <elmgameinfo@gmail.com>
This commit is contained in:
elm
2026-02-04 16:08:32 +09:00
committed by GitHub
parent b7900a24a0
commit 519aa2b2bf
21 changed files with 473 additions and 454 deletions

View File

@@ -10,6 +10,7 @@ use cef::{Settings, api_hash, execute_process, initialize, shutdown, sys};
/// - macOS: Calls [`CefDoMessageLoopWork`](https://cef-builds.spotifycdn.com/docs/106.1/cef__app_8h.html#a830ae43dcdffcf4e719540204cefdb61) every frame.
pub struct MessageLoopPlugin {
pub config: CommandLineConfig,
pub extensions: CefExtensions,
}
impl Plugin for MessageLoopPlugin {
@@ -21,7 +22,8 @@ impl Plugin for MessageLoopPlugin {
let args = Args::new();
let (tx, rx) = std::sync::mpsc::channel();
let mut cef_app = BrowserProcessAppBuilder::build(tx, self.config.clone());
let mut cef_app =
BrowserProcessAppBuilder::build(tx, self.config.clone(), self.extensions.clone());
let ret = execute_process(
Some(args.as_main_args()),
Some(&mut cef_app),

View File

@@ -16,12 +16,12 @@ use crate::mute::AudioMutePlugin;
use crate::prelude::{IpcPlugin, NavigationPlugin, WebviewPlugin};
use crate::zoom::ZoomPlugin;
use bevy::prelude::*;
use bevy_cef_core::prelude::CommandLineConfig;
use bevy_cef_core::prelude::{CefExtensions, CommandLineConfig};
use bevy_remote::RemotePlugin;
pub mod prelude {
pub use crate::{CefPlugin, RunOnMainThread, common::*, navigation::*, webview::prelude::*};
pub use bevy_cef_core::prelude::CommandLineConfig;
pub use bevy_cef_core::prelude::{CefExtensions, CommandLineConfig};
}
pub struct RunOnMainThread;
@@ -29,6 +29,7 @@ pub struct RunOnMainThread;
#[derive(Debug, Default)]
pub struct CefPlugin {
pub command_line_config: CommandLineConfig,
pub extensions: CefExtensions,
}
impl Plugin for CefPlugin {
@@ -37,6 +38,7 @@ impl Plugin for CefPlugin {
LocalHostPlugin,
MessageLoopPlugin {
config: self.command_line_config.clone(),
extensions: self.extensions.clone(),
},
WebviewCoreComponentsPlugin,
WebviewPlugin,