JDK-8281051 : HCAPTCHA not supported in JRE 8u321
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2022-01-29
  • Updated: 2022-10-28
  • Resolved: 2022-02-01
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Well work with RECAPTCHA, but Loop of the HCAPTCHA : is considered as a robot

REGRESSION : Last worked in version 8u321


---------- BEGIN SOURCE ----------
package _TEST;

import java.awt.BorderLayout;
import java.io.File;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.sun.javafx.application.PlatformImpl;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.concurrent.Worker.State;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class CL_Application extends JFrame {

	private static final long serialVersionUID = 1L;

	public static void main(String[] args) {
		new CL_Application();
	}
	
	public CL_Application() {
		System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
		
		JPanel webBrowser = new CL_SwingFXWebView();
		getContentPane().add(webBrowser, BorderLayout.CENTER);
		setSize(800, 600);
		setVisible(true);
		
		((CL_SwingFXWebView)webBrowser).load("https://www.pagesjaunes.fr");
	}
	
	class CL_SwingFXWebView extends JPanel {  

		private static final long serialVersionUID = 8990771757800321056L;

		private Stage stage = null;  
	    private WebView browser = null;  
	    private JFXPanel jfxPanel = null;
	    private WebEngine webEngine = null;  

	    public CL_SwingFXWebView() {
	        jfxPanel = new JFXPanel();  
	        
	        PlatformImpl.startup(new Runnable() {  

	            public void run() {  					
					stage = new Stage();
	                Group root = new Group();  
	                Scene scene = new Scene(root);
	                stage.setScene(scene);  

	                browser = new WebView();
	                browser.setCache(true);
	                webEngine = browser.getEngine();
	                webEngine.setUserDataDirectory(new File("."));
	                //webEngine.setUserAgent("use required / intended UA string");
	                webEngine.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134");
	                webEngine.setJavaScriptEnabled(true);
	               
	            	TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
	    				
	    				public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws java.security.cert.CertificateException {}

	    				public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException {}
	    				
	    				public java.security.cert.X509Certificate[] getAcceptedIssuers() {
	    					return null; //new java.security.cert.X509Certificate[] {};
	    				}
	    			}};

	    			SSLContext sc = null;
	    			try {
	    				sc = SSLContext.getInstance("SSL");
	    				sc.init(null, trustAllCerts, new java.security.SecureRandom());
	    			} catch (NoSuchAlgorithmException e) {
	    				e.printStackTrace();
	    			} catch (KeyManagementException e) {
	    				e.printStackTrace();
	    			}

	    			HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

	    			HostnameVerifier allHostsValid = new HostnameVerifier() {
	    				public boolean verify(String hostname, SSLSession session) {
	    					return true;
	    				}
	    			};

	    			HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

	        		webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
		            	
	        			public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
	        	                       
	        				if (newState == State.RUNNING) {
	        				}
	        				
	        				if (newState == State.SUCCEEDED) {
	        				}
	        			}
	        		});
	        		
	                ObservableList<Node> children = root.getChildren();
	                children.add(browser);                     

	                jfxPanel.setScene(scene);  
	            }  
	        });
	        
	        setLayout(new BorderLayout());  
	        add(jfxPanel, BorderLayout.CENTER);
	    }

	    public void load(final String _sURL) {
	        
	    	Platform.runLater(new Runnable() {

	        	public void run() {
	        		webEngine.load(_sURL);
	        	}
	        });
	    }
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
THE SOLUTION webEngine.setUserAgent("use required / intended UA string"); NOT WORKING

FREQUENCY : always



Comments
Relates to JDK-8281048 from the same submitter
28-10-2022