Access all the cookies from a JavaFX WebView

后端 未结 2 550
野性不改
野性不改 2021-01-07 09:52

I need to access all the cookies from a JavaFX WebView. As far as I can see there\'s a com.sun.webkit that implements its own CookieManager, Cookie, etc, etc. In that implem

2条回答
  •  终归单人心
    2021-01-07 10:31

    There is no direct way in java as far as I know, but you can communicate with the javascript side of a webPage, meaning you could do something like this: (not tested!)

    WebView wv; //assumed to be initialized
    WebEngine we = wv.getEngine();
    String cookie = (String)we.executeScript("return document.cookie"):
    

    Yes this means you got the usual restrictions to coockie acces as you normally have in javascript. But it might be enough in your case.

    EDIT:

    Apparently its also possible using the java.net library (e.g. java.net.CoockieHandler.getDefault()). In this SO post you can find a bit more on how to use it, and here is the CoockieManager documentation.

提交回复
热议问题