Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

windows - Javafx - open login.microsoftonline.com page in webview component

I have problem with opening login.microsoftonline.com page in webview component from javafx. I have simply code that should open this page without any trouble:

   WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    var url = "https://login.microsoftonline.com/";
    webEngine.load(url);

    VBox root = new VBox();
    root.getChildren().add(webView);
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    webEngine.getLoadWorker().stateProperty().addListener((obs, oldValue, newValue) -> { 
     System.out.println(webEngine.getLocation());
    });

When I try to execute this code on machine with windows operating system I receive blank page: enter image description here When I execute the same code on macbook, site is opening: enter image description here

I'm using java 10 and really no idea what's wrong. Does anybody have the same issue? Any idea how to solve this problem? maybe there is other component instead of webview that I can use to do my stuff?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is not the solution to your problem but may lead you in the right direction. It seems that the site body is loaded using script. That script depends on other scripts I am guessing. It appears none of the other scripts are loading.

import com.sun.javafx.webkit.WebConsoleListener;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

/**
 *
 * @author blj0011
 */
public class JavaFXApplication281 extends Application
{

    @Override
    public void start(Stage primaryStage)
    {
        try {
            TrustManager trm = new X509TrustManager()
            {
                @Override
                public X509Certificate[] getAcceptedIssuers()
                {
                    return null;
                }

                @Override
                public void checkClientTrusted(X509Certificate[] certs, String authType)
                {
                }

                @Override
                public void checkServerTrusted(X509Certificate[] certs, String authType)
                {
                }
            };

            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, new TrustManager[]{trm}, null);
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

            WebView webView = new WebView();
            WebEngine webEngine = webView.getEngine();
            WebConsoleListener.setDefaultListener(new WebConsoleListener()
            {
                @Override
                public void messageAdded(WebView webView, String message, int lineNumber, String sourceId)
                {
                    System.out.println("Console: [" + sourceId + ":" + lineNumber + "] " + message);
                }
            });
            webEngine.setJavaScriptEnabled(true);
            String url = "https://login.microsoftonline.com/";//"https://login.microsoftonline.com/jsdisabled";//
            webEngine.load(url);

            webEngine.getLoadWorker().stateProperty().addListener((obs, oldValue, newValue) -> {
                System.out.println(newValue);
                String html = (String) webEngine.executeScript("document.documentElement.outerHTML");
                System.out.println(html);
            });

            webEngine.setOnError((event) -> {
                System.out.println(event.getMessage());
            });
//        webEngine.getLoadWorker().exceptionProperty().addListener((obs, oldExc, newExc) -> {
//            if (newExc != null) {
//                newExc.printStackTrace();
//            }
//        });
            StackPane root = new StackPane();

            root.getChildren().add(webView);

            Scene scene = new Scene(root, 300, 250);

            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
        }
        catch (KeyManagementException ex) {
            ex.printStackTrace();
        }
        catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        launch(args);
    }

}

Output:

Console: [null:0] Cannot load stylesheet https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/converged.v2.login.min_jumzhgrnvlj7lwxqltrteq2.css. Failed integrity metadata check.
Console: [https://login.microsoftonline.com/common/oauth2/authorize?client_id=4345a7b9-9a63-4910-a426-35363201d503&response_mode=form_post&response_type=code+id_token&scope=openid+profile&state=OpenIdConnect.AuthenticationProperties%3d5xhL9s5iN_65agH7ctGnRfQlJHUHgSrEvD4vkaO323RyB1klBHD6Qh5qidm6GuaIHM8_GaSANKH6y1ohWHalX4QU_YyqGJqXV8wphi2TVMAAY3yyXQk3GB-yqWm0j3oh&nonce=636748812038183968.MmMxNjY2YjEtNDIwZS00ZDhhLWI3YmItMWRhMWM5ZmRmMzk4MjJkMGExMDItZDAxZi00MTZmLWIxYjctOTNmZWU2YjgzZDRi&redirect_uri=https%3a%2f%2fwww.office.com%2f&ui_locales=en-US&mkt=en-US:30] Cannot load stylesheet https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/converged.v2.login.min_jumzhgrnvlj7lwxqltrteq2.css. Failed integrity metadata check.
Console: [https://login.microsoftonline.com/common/oauth2/authorize?client_id=4345a7b9-9a63-4910-a426-35363201d503&response_mode=form_post&response_type=code+id_token&scope=openid+profile&state=OpenIdConnect.AuthenticationProperties%3d5xhL9s5iN_65agH7ctGnRfQlJHUHgSrEvD4vkaO323RyB1klBHD6Qh5qidm6GuaIHM8_GaSANKH6y1ohWHalX4QU_YyqGJqXV8wphi2TVMAAY3yyXQk3GB-yqWm0j3oh&nonce=636748812038183968.MmMxNjY2YjEtNDIwZS00ZDhhLWI3YmItMWRhMWM5ZmRmMzk4MjJkMGExMDItZDAxZi00MTZmLWIxYjctOTNmZWU2YjgzZDRi&redirect_uri=https%3a%2f%2fwww.office.com%2f&ui_locales=en-US&mkt=en-US:30] Cannot load stylesheet https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/converged.v2.login.min_jumzhgrnvlj7lwxqltrteq2.css. Failed integrity metadata check.
Console: [https://login.microsoftonline.com/common/oauth2/authorize?client_id=4345a7b9-9a63-4910-a426-35363201d503&response_mode=form_post&response_type=code+id_token&scope=openid+profile&state=OpenIdConnect.AuthenticationProperties%3d5xhL9s5iN_65agH7ctGnRfQlJHUHgSrEvD4vkaO323RyB1klBHD6Qh5qidm6GuaIHM8_GaSANKH6y1ohWHalX4QU_YyqGJqXV8wphi2TVMAAY3yyXQk3GB-yqWm0j3oh&nonce=636748812038183968.MmMxNjY2YjEtNDIwZS00ZDhhLWI3YmItMWRhMWM5ZmRmMzk4MjJkMGExMDItZDAxZi00MTZmLWIxYjctOTNmZWU2YjgzZDRi&redirect_uri=https%3a%2f%2fwww.office.com%2f&ui_locales=en-US&mkt=en-US:30] Failed to load external resource ['https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/converged.v2.login.min_jumzhgrnvlj7lwxqltrteq2.css']
Console: [null:0] Cannot load script https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/oldconvergedlogin_pcore.min_lwozjqawrstmtzsn2yunha2.js. Failed integrity metadata check.
Console: [null:0] Cannot load script https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/convergedloginpaginatedstrings-en.min_uzcugprrg6vz0z16am4meq2.js. Failed integrity metadata check.
Console: [null:0] Cannot load script https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/oldconvergedlogin_pcore.min_lwozjqawrstmtzsn2yunha2.js. Failed integrity metadata check.
Console: [null:0] Cannot load script https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/convergedloginpaginatedstrings-en.min_uzcugprrg6vz0z16am4meq2.js. Failed integrity metadata check.
Console: [null:0] Cannot load script https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/oldconvergedlogin_pcore.min_lwozjqawrstmtzsn2yunha2.js. Failed integrity metadata check.
Console: [https://login.microsoftonline.com/common/oauth2/authorize?client_id=4345a7b9-9a63-4910-a426-35363201d503&response_mode=form_post&response_type=code+id_token&scope=openid+profile&state=OpenIdConnect.AuthenticationProperties%3d5xhL9s5iN_65agH7ctGnRfQlJHUHgSrEvD4vkaO323RyB1klBHD6Qh5qidm6GuaIHM8_GaSANKH6y1ohWHalX4QU_YyqGJqXV8wphi2TVMAAY3yyXQk3GB-yqWm0j3oh&nonce=636748812038183968.MmMxNjY2YjEtNDIwZS00ZDhhLWI3YmItMWRhMWM5ZmRmMzk4MjJkMGExMDItZDAxZi00MTZmLWIxYjctOTNmZWU2YjgzZDRi&redirect_uri=https%3a%2f%2fwww.office.com%2f&ui_locales=en-US&mkt=en-US:30] Failed to load external resource ['https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/oldconvergedlogin_pcore.min_lwozjqawrstmtzsn2yunha2.js']
Console: [null:0] Cannot load script https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/convergedloginpaginatedstrings-en.min_uzcugprrg6vz0z16am4meq2.js. Failed integrity metadata check.
Console: [https://login.microsoftonline.com/common/oauth2/authorize?client_id=4345a7b9-9a63-4910-a426-35363201d503&response_mode=form_post&response_type=code+id_token&scope=openid+profile&state=OpenIdConnect.AuthenticationProperties%3d5xhL9s5iN_65agH7ctGnRfQlJHUHgSrEvD4vkaO323RyB1klBHD6Qh5qidm6GuaIHM8_GaSANKH6y1ohWHalX4QU_YyqGJqXV8wphi2TVMAAY3yyXQk3GB-yqWm0j3oh&nonce=636748812038183968.MmMxNjY2YjEtNDIwZS00ZDhhLWI3YmItMWRhMWM5ZmRmMzk4MjJkMGExMDItZDAxZi00MTZmLWIxYjctOTNmZWU2YjgzZDRi&redirect_uri=https%3a%2f%2fwww.office.com%2f&ui_locales=en-US&mkt=en-US:30] Failed to load external resource ['https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8233.17/content/cdnbundles/convergedloginpaginatedstrings-en.min_uzcugprrg6vz0z16am4meq2.js']

The above will also show you the HTML that was loaded. It is too long to add.

Some code from here to help troubleshoot the problem.

I do not have Java 10. I used Java 8.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...