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:
parent
5a8d10fff4
commit
204c9b60fe
1 changed files with 5 additions and 1 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue