From 1dd396c252063fed83572cd47878f51f9fbbef9a Mon Sep 17 00:00:00 2001 From: Takagi Tasuku Date: Mon, 2 Feb 2026 18:51:56 +0900 Subject: [PATCH 1/3] fix: port missing early returns in BrowserSideRouter and BrowserInfoMap Ensures behavior matches the original CEF C++ implementation by adding early returns when maps are empty or entries are missing. This fixes a panic in `BrowserSideRouter::find_browser_all`. Reference C++ implementation: - BrowserSideRouter: https://github.com/chromiumembedded/cef/blob/5f93c2b090d19659451de4dfe44896ad7dbfd832/libcef_dll/wrapper/cef_message_router.cc#L535-L537 - BrowserInfoMap: https://github.com/chromiumembedded/cef/blob/5f93c2b090d19659451de4dfe44896ad7dbfd832/libcef_dll/wrapper/cef_browser_info_map.h#L159-L167 --- cef/src/wrapper/browser_info_map.rs | 11 +++++++---- cef/src/wrapper/message_router.rs | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cef/src/wrapper/browser_info_map.rs b/cef/src/wrapper/browser_info_map.rs index 0731109f..787685d6 100644 --- a/cef/src/wrapper/browser_info_map.rs +++ b/cef/src/wrapper/browser_info_map.rs @@ -107,10 +107,13 @@ impl BrowserInfoMap { /// Find all objects associated with the specified browser. If any objects are /// removed using the Visitor the caller is responsible for destroying them. pub fn find_browser_all(&mut self, browser_id: i32, visitor: &dyn BrowserInfoMapVisitor) { - let info_map = self - .map - .get_mut(&browser_id) - .expect("missing browser info map"); + if self.map.is_empty() { + return; + } + + let Some(info_map) = self.map.get_mut(&browser_id) else { + return; + }; let mut removed = vec![]; let keys: Vec<_> = info_map.keys().copied().collect(); diff --git a/cef/src/wrapper/message_router.rs b/cef/src/wrapper/message_router.rs index f0487cfd..281c3778 100644 --- a/cef/src/wrapper/message_router.rs +++ b/cef/src/wrapper/message_router.rs @@ -666,6 +666,10 @@ impl BrowserSideRouter { return; }; + if browser_query_info_map.is_empty() { + return; + } + struct Visitor { router: Arc, handler_id: Option, From e61fed1564249e59aaff714333cda7832efdb5d4 Mon Sep 17 00:00:00 2001 From: Takagi Tasuku Date: Tue, 3 Feb 2026 15:37:36 +0900 Subject: [PATCH 2/3] fix: return string responses as V8 strings instead of ArrayBuffer from RendererSideRouter When sending a success response back to JavaScript, MessagePayload::String should be created as a V8 string to match the original CEF behavior. This commit fixes the issue where MessagePayload::String was incorrectly handled as binary data. --- cef/src/wrapper/message_router.rs | 45 ++++++++++++++++++------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/cef/src/wrapper/message_router.rs b/cef/src/wrapper/message_router.rs index 281c3778..dd92b4dc 100644 --- a/cef/src/wrapper/message_router.rs +++ b/cef/src/wrapper/message_router.rs @@ -1326,28 +1326,35 @@ impl RendererSideRouter { let Some(mut context) = self.get_context_by_id(context_id) else { return; }; - if context.enter() == 0 { - return; - } - let data = match &response { - mru::MessagePayload::Empty => &[], - mru::MessagePayload::String(s) => s.as_slice().unwrap_or(&[]), - mru::MessagePayload::Binary(b) => b.data(), - }; + let value = match &response { + mru::MessagePayload::String(s) => v8_value_create_string(Some(&s.into())), + mru::MessagePayload::Empty | mru::MessagePayload::Binary(_) => { + let data = match &response { + mru::MessagePayload::Binary(b) => b.data(), + _ => &[], + }; - #[cfg(feature = "sandbox")] - let value = v8_value_create_array_buffer_with_copy(data.as_ptr() as *mut u8, data.len()); - #[cfg(not(feature = "sandbox"))] - let value = v8_value_create_array_buffer( - data.as_ptr() as *mut u8, - data.len(), - Some(&mut mru::BinaryValueArrayBufferReleaseCallback::new( - response, - )), - ); + if context.enter() == 0 { + return; + } - context.exit(); + #[cfg(feature = "sandbox")] + let value = + v8_value_create_array_buffer_with_copy(data.as_ptr() as *mut u8, data.len()); + #[cfg(not(feature = "sandbox"))] + let value = v8_value_create_array_buffer( + data.as_ptr() as *mut u8, + data.len(), + Some(&mut mru::BinaryValueArrayBufferReleaseCallback::new( + response, + )), + ); + + context.exit(); + value + } + }; success_callback.execute_function_with_context(Some(&mut context), None, Some(&[value])); } From ab8db75d1a0724f945b231869161c2aeef47e469 Mon Sep 17 00:00:00 2001 From: Takagi Tasuku Date: Wed, 4 Feb 2026 00:51:44 +0900 Subject: [PATCH 3/3] docs: update CHANGELOG.md for message router fixes --- cef/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cef/CHANGELOG.md b/cef/CHANGELOG.md index 992183f5..ebf5e617 100644 --- a/cef/CHANGELOG.md +++ b/cef/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- port missing early returns in BrowserSideRouter and BrowserInfoMap to prevent panics during startup +- return string responses as V8 strings instead of ArrayBuffer from RendererSideRouter + ## [144.0.1+144.0.6](https://github.com/tauri-apps/cef-rs/compare/cef-v144.0.0+144.0.6...cef-v144.0.1+144.0.6) - 2026-01-22 ### Other