JBCefBrowser how to handle JavaScript events or pass data from JavaScript to Java/Kotlin code?

Answered

Hello,

 

I created simple plugin with JBCefBrowser. I need to handle button or link click and get data from JavaScript in Java/Kotlin code on this JS event. 

How to do it?

Thank you!

0
2 comments

Hello! Try to use org.cef.handler.CefMessageRouterHandler :)

 

0

Ok. Created next solution

val javaScriptEngineProxy: JBCefJSQuery = JBCefJSQuery.create(browser as JBCefBrowserBase)

javaScriptEngineProxy.addHandler { result ->
println(result)

null
}

val injectedJavaScript = """
window.goToLine = function() {
var filePath = document.getElementById("go-to-filepath").value
var lineNumber = document.getElementById("go-to-line-number").value
var goToPath = filePath + ":" + lineNumber
${javaScriptEngineProxy.inject("goToPath")}
}

""".trimIndent()

browser.cefBrowser.executeJavaScript(injectedJavaScript, browser.cefBrowser.url, 0)

 

 

0

Please sign in to leave a comment.