0

I am trying to create a JavaFX application with a WebView that simply loads the "WhatsApp Web" site.

Code

public class Controller implements Initializable {

    @FXML
    private WebView webView;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        WebEngine webEngine = webView.getEngine();
        webEngine.setJavaScriptEnabled(true);
        webEngine.load("https://web.whatsapp.com/");
    }
}

When I run the program the following will show up

enter image description here

1. Question Why is this happening? Is there anything Javas WebEngine can't do?

2. Question How can I solve this?

Before someone asks why I would do this, instead of just using my regular browser - simply for fun and to understand how things work.

buræquete
  • 14,226
  • 4
  • 44
  • 89
  • 1
    Probably the server-side code is checking the HTTP request for a user-agent header, and if it doesn't indicate one of the supported browsers, it's returning the HTML you show. See https://stackoverflow.com/questions/45292054/detect-javafx-webview – James_D Nov 22 '17 at 18:28
  • Seems like the whatsapp site detects you using a different browser than the standard ones. Maybe you can work around that by setting `WebEngine`'s `userAgent` property... – fabian Nov 22 '17 at 18:28
  • @fabian I already tried to set the user agent to something else. When I read out the default user agent it says "Mozilla/5.0 (Linux x86_64) AppleWebKit/604.1 (KHTML, like Gecko) JavaFX/9 Safari/604.1" –  Nov 22 '17 at 18:59
  • @James_D that's what I thought and leads me to question 2. Is there any way I can manipulate the header so the server thinks that I'm using the right engine/browser. –  Nov 22 '17 at 20:15
  • @jslr Isn't that what the question I linked tells you how to do? – James_D Nov 22 '17 at 20:15
  • @James_D not really. I changed the user agent to what is referred here https://developer.mozilla.org/de/docs/Web/HTTP/Headers/User-Agent but it is still not accepting my requests. I also tried to read out the packets via wireshark but couldn't find any difference to what is sent when I access whatsapp web via firefox. –  Nov 22 '17 at 20:17

0 Answers0