模拟器在执行时挂起 browserComponent.executeAndReturnString("navigator.userAgent"

Simulator hangs con execute browserComponent.executeAndReturnString("navigator.userAgent"

在模拟器上 App 在执行时挂起 browserComponent.executeAndReturnString("navigator.userAgent")

        BrowserComponent browserComponent = new BrowserComponent();
        String userAgent = (String) browserComponent.executeAndReturnString("navigator.userAgent");
        String userAgent = "";
        if (userAgent == null) {
            userAgent = "";
        }

在控制台日志上:

Using:
JCEF Version = 83.4.0.260
CEF Version = 83.4.0
Chromium Version = 83.0.4103.106
initialize on Thread[AWT-EventQueue-0,6,main] with library path C:\Users\Kandy\.codenameone\cef\lib\win64
Added scheme search://
Added scheme client://
Added scheme cn1stream://

DevTools listening on ws://127.0.0.1:53523/devtools/browser/2da17f15-4c86-45d2-98d2-c853b71d3d7a
AppHandler.stateHasChanged: NEW
AppHandler.stateHasChanged: INITIALIZING

虽然这个 API 没有被弃用,但在 JavaDocs 中强烈建议不要使用它,以支持 this

尝试:

bc.execute("navigator.userAgent", userAgent -> {
   // ... 
});

请注意,用户代理是您在浏览器组件中 submit/set 的东西,因此您可以确定它。