From 204c9b60fe81a0873b4010772aa97c9fd25ab46b Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 26 Mar 2026 14:29:32 -0700 Subject: [PATCH] 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. --- .../continueintellijextension/browser/ContinueBrowser.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowser.kt index 914a87f09..e4380d311 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/browser/ContinueBrowser.kt @@ -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) } }