Closed wangzhigang1112 closed 1 week ago
Screenshots info:
code:
Column { AppletNavigator(composeWindow, windowState).navigator(appletAction) SwingPanel(factory = { EpointWebView(murl, appletAction) }, modifier = Modifier.fillMaxSize()) }
`
class EpointWebView(url: String, action: AppletAction) : JFXPanel() {
private val mUrl: String
private val mAction: AppletAction
private lateinit var webEngine: WebEngine
init {
this.mUrl = url
this.mAction = action
this.mAction.epointWebView = this
Platform.runLater(::initJavaFxScene)
}
private fun initJavaFxScene() {
val webView = WebView()
val scene = Scene(webView)
setScene(scene)
webEngine = webView.engine
//setting
webSetting(webEngine)
webEngine.load(mUrl)
//delete cookies
CookieHandler.setDefault(CookieManager())
}
private fun webSetting(webEngine: WebEngine) {
webEngine.setOnAlert { eventArgs ->
val message = eventArgs.data
showAlert(message)
}
val userAgent =
"User-Agent: Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36 Edg/111.0.0.0" + " /EpointMiniH5/EpointEJS/"
// "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0" webEngine.setUserAgent(userAgent) setJSObject(webEngine)
webEngine.userStyleSheetLocation = Repository.getResource("applet/css/style.css")
}
private val logger: Logger? = LoggerFactory.getLogger(EpointWebView::class.java)
private fun setJSObject(webEngine: WebEngine) {
val ejs = EpointJSBridge(webEngine, mAction)
webEngine.promptHandler = Callback { param ->
val msg: String? = param?.message;
val defaultValue: String? = param?.defaultValue;
msg?.startsWith("", true).let {
if (it == true) {
ejs.prompt(msg ?: "", defaultValue ?: "")
}
}
""
}
}
fun showAlert(message: String?) {
val alertRunnable = Runnable {
val alert = Alert(AlertType.INFORMATION)
alert.title = "Epoint EJS Alert"
alert.headerText = message
alert.showAndWait()
}
Platform.runLater(alertRunnable)
}
fun goBack() {
Platform.runLater {
if (webEngine.history.currentIndex > 0) {
webEngine.history.go(-1)
}
}
}
`
console output:
Caused by: java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because the return value of "com.sun.webkit.WebPage.getClientCommittedText()" is null at com.sun.javafx.webkit.InputMethodClientImpl.getCommittedText(InputMethodClientImpl.java:185) at javafx.scene.Scene$InputMethodRequestsDelegate.getCommittedText(Scene.java:4211) at javafx.embed.swing.InputMethodSupport$InputMethodRequestsAdapter.getCommittedText(InputMethodSupport.java:83) at java.desktop/sun.awt.im.InputMethodContext.getCommittedText(InputMethodContext.java:302) at java.desktop/sun.lwawt.macosx.CInputMethod$3.run(CInputMethod.java:607) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:308) at java.desktop/sun.awt.AWTThreading$TrackedInvocationEvent.lambda$dispatch$3(AWTThreading.java:310) at java.desktop/sun.awt.AWTThreading$TrackedInvocationEvent.completeIfNotYet(AWTThreading.java:323) at java.desktop/sun.awt.AWTThreading$TrackedInvocationEvent.dispatch(AWTThreading.java:310) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:779) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:754) at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:752) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:751) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92) java.lang.reflect.InvocationTargetException at java.desktop/sun.lwawt.macosx.LWCToolkit.checkException(LWCToolkit.java:843) at java.desktop/sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:806) at java.desktop/sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:744) at java.desktop/sun.lwawt.macosx.CInputMethod.invokeAndWaitNoThrow(CInputMethod.java:884) at java.desktop/sun.lwawt.macosx.CInputMethod.attributedSubstringFromRange(CInputMethod.java:594)
Thanks for the bug description. Can you please provide a minimal reproducible sample project on GitHub?
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Describe the bug Using javafx's webview control, the console keeps printing this bug when loading a web page with a listening input box: Cannot invoke "String.substring(int, int)" because the return value of "com.sun.webkit.WebPage.getClientCommittedText()" is null
Affected platforms Select one of the platforms below:
Versions
To Reproduce Steps and/or the code snippet to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
Screenshots code: ![Uploading image.png…]() ![Uploading image.png…]()
console output: ![Uploading image.png…]()
Additional context Add any other context about the problem here.