JetBrains / JetBrainsRuntime

Runtime environment based on OpenJDK for running IntelliJ Platform-based products on Windows, macOS, and Linux
GNU General Public License v2.0
1.35k stars 198 forks source link

can't invoke native method 'updateUI' before native context initialized #424

Closed starxg closed 3 months ago

starxg commented 4 months ago

Describe the bug Unable to start browser

Screenshots

image

Version and environment:

Additional context Code:

import org.cef.CefApp;
import org.cef.CefClient;
import org.cef.CefSettings;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefRendering;

import javax.swing.*;

public class Demo {
    public static void main(String[] args) {
        final CefSettings cefSettings = new CefSettings();
        cefSettings.windowless_rendering_enabled = false;

        final CefApp cefApp = CefApp.getInstance(cefSettings);
        System.out.println(cefApp.getVersion());

        final CefClient cefClient = cefApp.createClient();
        final CefBrowser browser = cefClient.createBrowser("https://www.baidu.com", CefRendering.DEFAULT, true);

        final JFrame frame = new JFrame();
        frame.setTitle("Test");
        frame.add(browser.getUIComponent());
        frame.setSize(500, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

Logs:

JCEF(20:36:787): initialized stderr logger, severity=LOGSEVERITY_DEFAULT
JCEF_I(20:36:794): CefApp: set state NEW
JCEF_E(20:36:984): Failed to get CEF version. 'org.cef.CefApp$CefVersion org.cef.CefApp.N_GetVersion()'
null
JCEF_E(20:37:179): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:179): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:179): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'notifyMoveOrResizeStarted' before native context initialized
2024-07-25 23:20:37.213 java[149:12030038] === getJavaWindowTabbingMode: 0 ===
JCEF_E(20:37:310): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'setParent' before native context initialized
JCEF_E(20:37:313): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:314): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:314): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'wasResized' before native context initialized
JCEF_E(20:37:315): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:316): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'notifyMoveOrResizeStarted' before native context initialized
JCEF_E(20:37:316): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
2024-07-25 23:20:37.330 java[149:12030038] became key: 0 Test (null)
2024-07-25 23:20:37.330 java[149:12030038] became main: 1 Test (null)
JCEF_E(20:37:351): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'setWindowVisibility' before native context initialized
JCEF_E(20:37:352): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:368): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'setFocus' before native context initialized
JCEF_E(20:37:368): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_E(20:37:368): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'notifyMoveOrResizeStarted' before native context initialized
JCEF_E(20:37:376): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'updateUI' before native context initialized
JCEF_V(20:37:482): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: add delayed action createBrowser
2024-07-25 23:20:39.386 java[149:12030038] resigned main: 1 Test (null)
2024-07-25 23:20:39.386 java[149:12030038] resigned key: 0 Test (null)
2024-07-25 23:20:39.386 java[149:12030038] deactivating window: Test
JCEF_E(20:39:389): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'setWindowVisibility' before native context initialized
JCEF_E(20:39:390): CefBrowser_N: org.cef.browser.CefBrowserWr@2133814f: can't invoke native method 'setFocus' before native context initialized
starxg commented 3 months ago

It's work.

import com.jetbrains.cef.JCefAppConfig;
import org.cef.CefApp;
import org.cef.CefClient;
import org.cef.CefSettings;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefRendering;

import javax.swing.*;

public class Demo {
    public static void main(String[] args) {
        final JCefAppConfig jCefAppConfig = JCefAppConfig.getInstance();
        final CefSettings cefSettings = jCefAppConfig.getCefSettings();
        CefApp.startup(jCefAppConfig.getAppArgs());
        final CefApp cefApp = CefApp.getInstance(jCefAppConfig.getAppArgs(), cefSettings);

        System.out.println(cefApp.getVersion());

        final CefClient cefClient = cefApp.createClient();
        final CefBrowser browser = cefClient.createBrowser("https://www.baidu.com", CefRendering.DEFAULT, true);

        final JFrame frame = new JFrame();
        frame.setTitle("Test");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(browser.getUIComponent());
        frame.setSize(500, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}