Fork me on GitHub

Hi, I'm trying to use web-views and wondering how can I send an event from javascript to cljfx. any idea ?


what I ended up doing was using WebSockets via Sente ( to create an event bus, this is a little bit involved but ultimately has a nice property: you can transparently dispatch events between the webview and javafx bi-directionally using the same re-frame esque conventions (if you also plan on using ClojureScript in the Webview)


this doc describes how one can setup communication with the web page


you can access the web engine by creating custom props, for example


here are some examples of built-in custom props that access WebEngine:


thank you a lot, I was hoping for something builtin to cljfx, but it seems doable. So if I understand well, I will have to create my own lifecycle, which will setup the communication in its create method (by using WebEngine)?


you will create extension lifecycle that wraps web-view lifecycle:

(def ext-with-my-stuff 
    {:my-custom-prop-that-establishes-communication ...}))

{:fx/type ext-with-my-stuff
 :props {:my-custom-prop-that-establishes-communication ...}
 :desc {:fx/type :web-view


nice 🙂 I will start like this. thank you a lot for the help


I've got a java question (I'm not so much familiar with clj/java interop). I'm trying to make this snippet work in the context of my cljfx app: (its from the you've linked)

EventListener listener = new EventListener() {
        public void handleEvent(Event ev) {

    Document doc = webEngine.getDocument();
    Element el = doc.getElementById("exit-app");
    ((EventTarget) el).addEventListener("click", listener, false);
To be honest I don't even understand the first statement... And I don't know how can I translate it to clojure... sorry for the noobyness :)


first statement — you mean this?

EventListener listener = new EventListener() {
        public void handleEvent(Event ev) {


it’s like that in clojure:

(reify EventListener
  (handleEvent [this ev]


so it creates an instance of EventListener interface


@U0508P8EK seems appealing to be able to use clojurescript in a webview, i've tryed without success. do you have some code to show ?


@U47G49KHQ, ho! I'm surprised that it is so simple! thank you (looking at the javadoc I taught that I would need a proxy)


@U47G49KHQ, when I try to evaluate your expression I get this error

Syntax error (IllegalArgumentException) compiling reify* at (codemirror.clj:75:1).
Can't define method not in interfaces: handleEvent
Maybe EventListener is not what I taught it was. I'm using java.util.EventListener Am I missing something ?


yep, it’s


ok 🙂 thank you a lot


I found it like that: WebEngine’s document property is defined here: it returns a value of type “Document”, and it’s has a link leading here: So this is something from the JDK, and at that site I searched for addEventListener and found this:,,boolean)

🙏 3