I am trying to open a webview to Microsoft's auth v2. Loads fine in a browser, but in JavaFX's WebView (JDK 8) the page is blank. Once I turned on console output, I see many lines such as for both CSS and JS.
[null:0] Cannot load stylesheet https://secure.aadcdn.microsoftonline-p.com/ests/2.1.8148.16/content/cdnbundles/converged.v2.login.min_t7iocdq0wq2qh0nv233jig2.css. Failed integrity metadata check.
I am relatively sure that the issue is with CORS (I am loading microsoftonline.com
and the resources are on microsoftonline-p.com
). I've tried every possible fix that I can think of, or find online.
I have tried setting all of these
engine.setJavaScriptEnabled(true)
engine.setUserAgent("AppleWebKit/537.44")
System.setProperty("sun.net.http.allowRestrictedHeaders", "true")
I've also set the Property via -Dsun.net.http.allowRestrictedHeaders=true
in VMOptions
( as seen here ) and from the JavaFX issue JDK-8096797
The property shows up as set:
println(System.getProperty("sun.net.http.allowRestrictedHeaders"))
yields true
on the console printout.
Still no change, ever in the page output, it is always a white, blank screen, and the same errors from the web console.
I think I found the trouble lines in WebKit(see matchIntegrityMetadata
) even, but that didn't help me solve the problem any, because I don't know how to disable the integrityCheck.
This really, really has me stumped. Any help is very appreciated.
For reference, here is the entire method:
private fun WebView.authWindow(provider: Oath2Account){
engine.setUserAgent("AppleWebKit/537.44")
engine.setJavaScriptEnabled(true)
URLPermission("https://*.com")
System.setProperty("sun.net.http.allowRestrictedHeaders", "true")
Platform.runLater {
engine.userDataDirectory = File("C:\\users\\eric\\javafx_tmp")
engine.setOnError { println("IN PAGE ERROR --> $it") }
engine.setOnAlert { println("IN PAGE ALERT --> $it") }
engine.setConfirmHandler { println("IN PAGE CONFIRM HANDLER --> $it")
true
}
engine.setCreatePopupHandler { println("IN PAGE POPUP --> $it")
engine}
engine.setOnResized { println("IN PAGE RESIZED --> $it") }
engine.setOnStatusChanged { println("IN PAGE STATUS CHANGED --> $it")
println("\t${it.data}")
println("\t${it.source}")
println("\t${it.eventType}")
println("\t${it.target}")
println("\t${it.isConsumed}")
}
engine.setOnVisibilityChanged { println("IN PAGE VISIBILITY CHANGED --> $it") }
engine.setPromptHandler { println("IN PAGE PROMPTED --> $it")
"HELLO"}
println("JavaScript engine status: ${engine.isJavaScriptEnabled}")
println("engine is loading $loadURL")
engine.locationProperty().addListener { observable, oldLocation, newLocation->
println("observable=$observable\noldLocation=$oldLocation\nnewLocation=$newLocation")
// if (newLocation.startsWith("urn:ietf:wg:oauth:2.0:oob")) {
// val code:get
// val title:from
// val accessToken = service.getAccessToken(verifier)
// doSomething(accessToken.getAccessToken())
// }
}
com.sun.javafx.webkit.WebConsoleListener.setDefaultListener { webview, message, lineNumber, sourceId -> println("Console: [$sourceId:$lineNumber] $message") }
engine.setOnError({ event -> System.out.println(event.getMessage()) })
try{
engine.load(loadURL )
} catch (e: IOException) {
println("caught error:")
e.printStackTrace();
}
}