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

Joey Ruiz jacr2506 at
Mon Jun 17 22:35:32 UTC 2019

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