From d3428256543bcc5ab269df93c949b56df92793f2 Mon Sep 17 00:00:00 2001 From: liuk Date: Sat, 15 Mar 2025 19:44:32 +0800 Subject: [PATCH] fix: Eliminate Uncaught TypeError in dev tools --- .../toolWindow/ContinueBrowser.kt | 11 +++++++++-- .../toolWindow/ContinuePluginToolWindowFactory.kt | 7 +------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 4c2ad3b59..8cb700f15 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.ui.jcef.* +import com.intellij.ui.jcef.JBCefClient.Properties import org.cef.CefApp import org.cef.browser.CefBrowser import org.cef.handler.CefLoadHandlerAdapter @@ -32,10 +33,16 @@ class ContinueBrowser(val project: Project, url: String) { init { val isOSREnabled = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR - this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(isOSREnabled).build() + this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(isOSREnabled).build().apply { + // To avoid using System.setProperty to affect other plugins, + // we should configure JS_QUERY_POOL_SIZE after JBCefClient is instantiated, + // and eliminate the 'Uncaught TypeError: window.cefQuery_xxx is not a function' error + // in the JS debug console, which is caused by ContinueBrowser lazy loading. + jbCefClient.setProperty(Properties.JS_QUERY_POOL_SIZE, JS_QUERY_POOL_SIZE) + } registerAppSchemeHandler() - browser.loadURL(url); + browser.loadURL(url) Disposer.register(ContinuePluginDisposable.getInstance(project), browser) // Listen for events sent from browser diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt index d0d44655c..5d8335220 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt @@ -11,7 +11,7 @@ import com.intellij.openapi.wm.ToolWindowFactory import com.intellij.ui.content.ContentFactory import javax.swing.* -const val JS_QUERY_POOL_SIZE = "200" +const val JS_QUERY_POOL_SIZE = 200 class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware { override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { @@ -43,11 +43,6 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware { class ContinuePluginWindow(project: Project) { private val defaultGUIUrl = "http://continue/index.html" - init { - System.setProperty("ide.browser.jcef.jsQueryPoolSize", JS_QUERY_POOL_SIZE) - System.setProperty("ide.browser.jcef.contextMenu.devTools.enabled", "true") - } - val browser: ContinueBrowser by lazy { val url = System.getenv("GUI_URL")?.toString() ?: defaultGUIUrl