title: JavaFX WebView: can't get JS bridge to work in Java11+
body: <p>I can't get the Java / Javascript bridge to work on Java11 and Java13. The bridge seems to work fine i Java8 and Java10.</p>
  
  <p>Here is essentially the same code as <a href="https://stackoverflow.com/a/34840552/11329518">https://stackoverflow.com/a/34840552/11329518</a>, which again works for me on Java8 and Java10:</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import javafx.application.Application;
  import javafx.concurrent.Worker.State;
  import javafx.scene.control.ButtonType;
  import javafx.scene.web.WebEngine;
  import javafx.scene.web.WebEvent;
  import javafx.scene.web.WebView;
  import javafx.stage.Stage;
  import netscape.javascript.JSObject;
  
  public class Main extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
      JavaBridge bridge;
      WebEngine webEngine;
  
      @Override
      public void start(Stage primaryStage) throws MalformedURLException {
  
          final URL url = new File("C:/test.html").toURI().toURL();
  
          WebView webView = new javafx.scene.web.WebView();
          webEngine = webView.getEngine();
          webEngine.load(url.toExternalForm());
          webEngine.setJavaScriptEnabled(true);
          webEngine.setOnAlert(Main::showAlert);
          webEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -&gt; {
              if (newState == State.SUCCEEDED) {
                  System.out.println("READY");
                  JSObject jsobj = (JSObject) webEngine.executeScript("window");
                  bridge = new JavaBridge();
                  jsobj.setMember("bridge", bridge);
              }
  
          });
          primaryStage.setScene(new javafx.scene.Scene(webView, 300, 300));
          primaryStage.show();
      }
  
      // Shows the alert, used in JS catch statement
      private static void showAlert(WebEvent&lt;String&gt; event) {
          javafx.scene.control.Dialog&lt;ButtonType&gt; alert = new javafx.scene.control.Dialog&lt;&gt;();
          alert.getDialogPane().setContentText(event.getData());
          alert.getDialogPane().getButtonTypes().add(ButtonType.OK);
          alert.showAndWait();
      }
  
      public class JavaBridge {
          public void hello() {
              System.out.println("hello");
          }
      }
  }
  </code></pre>
  
  <p>with <code>test.html</code> containing the Javascript:</p>
  
  <pre class="lang-js prettyprint-override"><code>&lt;button onclick="try{bridge.hello();}catch(err){alert(err.message);}"&gt;call java&lt;/button&gt;
  </code></pre>
  
  <p>What's going on?</p>
  
  <p>I get the following error when clicking the button:</p>
  
  <p><code>bridge.hello is not a function. (In 'bridge.hello()', 'bridge.hello' is undefined)</code></p>