java-cef icon indicating copy to clipboard operation
java-cef copied to clipboard

entirely blank screen on JavaScript based websites when rendered in JPanel

Open felixlabrot opened this issue 1 year ago • 0 comments

Describe the bug When attempting to open web pages which don't contain HTML and instead are fully based on JavaScript (Angular, Node.js, ... based sites) the entire screen is blank. JCEF does not show the website and not produce any log output.

To Reproduce Open a website like https://klo.fyi/ or https://navi.graphhopper.org/ and observe a blank page.

Expected behavior The websites should open and be usable and not freeze.

Versions (please complete the following information):

  • OS: Windows 10
  • Java Version: Oracle JDK 8u202
  • JCEF Version: 127.3.1
  • CEF Version: jcef-99c2f7a+cef-127.3.1+g6cbb30e+chromium-127.0.6533.100

Additional context Does the problem reproduce with the JCEF simple or detailed sample application at the same version? no

Does the problem reproduce with Google Chrome at the same version? no

The following code is used and it follows exactly the Sample App. The only different thing is that it needs to render within a JPanel and not within a JFrame.

public class NavigationPanel extends JPanel {
    private static NavigationPanel INSTANCE;

    public static NavigationPanel getInstance() {
        if (INSTANCE == null)
            INSTANCE = new NavigationPanel();

        return INSTANCE;
    }

    private NavigationPanel() {
        setLayout(new GridLayout(1,1));

        Thread browserThread = new Thread("BrowserThread") {
            @Override
            public void run() {
                try {
                    CefAppBuilder builder = new CefAppBuilder();
                    CefSettings settings = builder.getCefSettings();
                    settings.windowless_rendering_enabled = false;
                    //settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_VERBOSE;
                    settings.root_cache_path = new File("jcef-cache").getAbsolutePath();

                    CefBrowser browser = builder.build().createClient().createBrowser("https://navi.graphhopper.org/", false, false);
                    NavigationPanel.this.add(browser.getUIComponent());
                } catch (CefInitializationException | UnsupportedPlatformException | IOException | InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        };

        browserThread.start();
    }
}

public class SampleApp extends JFrame {
    private SampleApp() {
        getContentPane().add(NavigationPanel.getInstance());
        setSize(800, 600);
        setVisible(true);
    }

    public static void main(String[] args) {
        new SampleApp();
    }
}

felixlabrot avatar Jan 02 '25 19:01 felixlabrot