fix: add guard for disposed JCEF browser in sendToWebview (#11897)

* fix: add guard for disposed JCEF browser in sendToWebview

Before calling executeJavaScript, check if the browser is already closed
to prevent NPE propagation from deeper in JCEF. Also broadens the catch
from IllegalStateException to Exception to handle NPE and other errors
that can occur when the browser is in a disposed state.

Fixes #8085, #9159

* fix: add log warning when sending to disposed browser

Log the message type before early-returning on a closed JCEF browser
to aid debugging silent message drops during project disposal.
This commit is contained in:
Dallin Romney 2026-03-26 14:29:32 -07:00 • committed by GitHub
parent 5a8d10fff4
commit 204c9b60fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -85,11 +85,15 @@ class ContinueBrowser(
}
fun sendToWebview(messageType: String, data: Any? = null, messageId: String = uuid()) {
if (browser.cefBrowser.isClosed) {
log.warn("Attempted to send message to disposed browser: $messageType")
return
}
val json = gsonService.gson.toJson(BrowserMessage(messageType, messageId, data))
val jsCode = """window.postMessage($json, "*");"""
try {
browser.cefBrowser.executeJavaScript(jsCode, getGuiUrl(), 0)
} catch (error: IllegalStateException) {
} catch (error: Exception) {
log.warn(error)
}
}