Interaction between JBCefBrowser JavaScript and Kotlin code
Hello, I am working on an IntelliJ plugin where I would like to render a graph in a webview which is part of a ToolWindow. I am using the JBCefBrowser for this, and I managed to initiate this browser with some static HTML. However ideally I want interactions between the browser it's JavaScript runtime, and my Kotlin plugin. For instance when I click on a button in the browser, I want to handle this by my Kotlin runtime to do open a certain file within the IDE. The other way around I might want to send some data from my Kotlin runtime into my JavaScript runtime. On internet I couldn't really find any good suggestions on how I could achieve this, would really appreciate if someone has some tips or recommendations.
Please sign in to leave a comment.
Hi Ramon,
Did you get familiar with this section? https://plugins.jetbrains.com/docs/intellij/jcef.html#executing-plugin-code-from-javascript
If it doesn't help, please describe your problem in more detail.
Hi Karol,
I noticed that the documentation you’re referring to seems to be outdated. Could you provide a more recent link or point me to the latest documentation?
For example, the method:
JBCefJSQuery openLinkQuery = JBCefJSQuery.create(browser); // 1
JBCefJSQuery.create()
is now marked as deprecated and is scheduled for removal. This change might affect how we initialize or interact with
JBCefBrowser
. I wanted to confirm if there’s a new recommended approach or if we should update our code accordingly.For what it is worth, this is how I implemented JBCefBrowser in the end:
https://github.com/ramonvermeulen/dbt-toolkit/blob/80b8791ba5558e0031858323b8c17aebea903b30/src/main/kotlin/com/github/ramonvermeulen/dbtToolkit/ui/panels/LineagePanel.kt#L63
e.g. receiving events from the JS runtime
sending events to JS runtime
Hi Info,
Only one
create
method is deprecated and it is mentioned in the docs to passJBCefBrowserBase
instance:If you pass
JBCefBrowserBase
, the non-depracted method will be used.