1

Is there any way I can get to the network traffic (requests and responses) being done by the JavaFX WebView control? From what I gather this is pretty much all native webkit, not even URLConnection is used, but maybe someone has a good idea.

I'm specifically interested in capturing the location header transmitted between two redirect responses (302), not the location the redirects will eventually be send to. So there is a request, it gets a 302, the new URL gets a 302 as well, and then the end location. I either need the location header in the first 302 response, or the second request's URL before it gets redirected.

tbeernot
  • 2,473
  • 4
  • 24
  • 31
  • Hm. Maybe it is possible to set a proxy... – tbeernot Oct 08 '21 at 05:06
  • It is, but the communication is HTTPS of course, so encrypted. :-/ – tbeernot Oct 08 '21 at 06:48
  • JavaFX WebView originally (e.g. for JavaFX 8) used the in-built URL handling and network stack of the Java platform. That meant you could define a custom URLStreamHandlerFactory to intercept all the WebView network traffic. I don't know if that is still the same with more recent JavaFX platforms. See [Custom JavaFX WebView Protocol Handler](https://stackoverflow.com/questions/17522343/custom-javafx-webview-protocol-handler) also see [Javafx webview http response data](https://stackoverflow.com/questions/17094990/javafx-webview-http-response-data) – jewelsea Oct 08 '21 at 07:30
  • Note the comment on that last linked question by Sean Reilly: . . . for javafx 12 and up the web engine uses an internal http implementation and not the URLStreamHandlerFactory. You can work around this by setting the "com.sun.webkit.useHTTP2Loader" system property to false, but it's not clear if that will stay a viable solution long-term. – jewelsea Oct 08 '21 at 07:32
  • What you may need to do to find your answer is to look at the internal WebView implementation, maybe search the source code for "com.sun.webkit.useHTTP2Loader" and see what that actually does. Then perhaps you can work out a way to hack the HTTP2Loader implementation to get the behavior you want if you can't just set that flag to false and use a URLStreamHandlerFactory. – jewelsea Oct 08 '21 at 07:36
  • "From what I gather this is pretty much all native webkit" -> I checked, this is wrong, it is the JEP 321 Java [http client api](https://docs.oracle.com/en/java/javase/17/docs/api/java.net.http/java/net/http/HttpClient.html), see [pr14](https://github.com/openjdk/jfx/pull/14) – jewelsea Oct 08 '21 at 08:01
  • If you navigate into openjfx's sources, you'll end up at WebPage which has a boat load of native method definitions. But I'll look into your suggestions ASAP, because they seem the only way that's left. https://github.com/openjdk/jfx/blob/master/modules/javafx.web/src/main/java/com/sun/webkit/WebPage.java#L2739 – tbeernot Oct 08 '21 at 20:24

0 Answers0