How to inject javascript function to be used before finishing loading dom in JavaFX

Bruno Borges bruno.borges at
Tue Jun 18 17:04:54 UTC 2019

Check the source code of my WebFX project. I hack the WebEngine dom object
to add some functions before things are loaded.

On Mon, Jun 17, 2019, 15:36 Joey Ruiz <jacr2506 at> wrote:

> I'm creating a javaFX browser integrated with a swing application. This
> browser opens a webpage that makes a call to a javascript function that
> should be injected befor the document finishes loading. Is there a way to
> do something similar to what BrowserFunction does for a SWT browser? So
> that way I can use the injected function any time and at any open page
> within the JavaFX browser.
> I just tried injecting the function with a member by using the JSObject
> class. This code is added in the loadWorker of the WebEngine with the
> stateProperty. I also tested it by adding this to the documentProperty by
> I'm still not able to make it work. The function is correctly added but
> it's not used because it seems to be injected after the document finished
> loading and I need it before that.
> window = (JSObject) engine.executeScript("window");
> window.setMember("app", jl);

More information about the openjfx-dev mailing list