At the beginning, I disabled the osr mode for all versions of ide, but the error “off-screen rendering mode is disabled: ‘ide.browser.jcef.osr.enabled=false’” appeared in the 2025 version of ide. So I set the 2025 version of osr mode to enable, but the jbcef browser page loading was slow or stuck.
Here is my code to create the browser:
public JBCefBrowserUi(Project project, String url){
this.url = url;
try {
setLayout(new GridBagLayout());
//禁用JBCefBrowser的OSR模式
if (!ApplicationInfo.getInstance().getFullVersion().startsWith("2025")){
Registry.get("ide.browser.jcef.osr.enabled").setValue(false);
}else {
Registry.get("ide.browser.jcef.osr.enabled").setValue(true);
}
createBrowser(project);
} catch (Exception e) {
SwingUtilities.invokeLater(() -> {
AiUtil.showNotifyInfo(project, e.getMessage());
});
throw new RuntimeException(e);
}
}
public void createBrowser(Project project){
if (jbCefBrowser != null){
jbCefBrowser.dispose();
}
jbCefBrowser = new JBCefBrowser(url);
developerHandle = new DeveloperHandle(this, project);
CefMessageRouter.CefMessageRouterConfig config = new CefMessageRouter.CefMessageRouterConfig();
config.jsQueryFunction = "javaQuery";// 定义方法
config.jsCancelFunction = "javaQueryCancel";// 定义取消方法
CefMessageRouter messageRouter = CefMessageRouter.create(config);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridy = 1;
c.gridx = 0;
c.gridwidth = 1;
c.weightx = 1;
c.weighty = 1;
removeAll();
add(jbCefBrowser.getComponent(), c);
}