Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use CefBrowser #31

Open
ara2am opened this issue Apr 10, 2020 · 2 comments
Open

How to use CefBrowser #31

ara2am opened this issue Apr 10, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ara2am
Copy link

ara2am commented Apr 10, 2020

Version: 0.3.3-online
JDK version: jdk1.8.0_231
Os and IDE of development: Win10 x64, Intelij IDEA

I want to load url, set user agent and set some simple listeners to cef.
But the simple code like :

JourneyBrowserView browser = new JourneyBrowserView ();
browser.getCefBrowser ().loadURL ("https://www.google.com");

Does nothing.

SwingUtilities.invokeLater (() ->
{
    browser.getCefBrowser ().loadURL ("https://www.google.com");
});

Doesn't work too.

But this code works:
JourneyBrowserView browser = new JourneyBrowserView ("https://www.google.com");

So, is it my blame or ...7

@BFergerson
Copy link
Owner

I'd recommend just setting the initial URL for now. If you are going to set the URL after loading the browser it has to be done after the browser has been created (see here).

Unfortunately, on Windows, you will run into an issue adding the CefLifeSpanHandler which is #13. I'll work on getting a fix for this in 0.4.1 as well but in the meantime you can remove the handler and re-add it manually, like so:

JourneyBrowserView browser = new JourneyBrowserView();
browser.getCefClient().removeLifeSpanHandler();
browser.getCefClient().addLifeSpanHandler(CefLifeSpanHandlerProxy.createHandler(new CefLifeSpanHandlerProxy() {
    @Override
    public boolean onBeforePopup(CefBrowserProxy browser, CefFrameProxy frame, String targetUrl, String targetFrameName) {
        return false;
    }

    @Override
    public void onAfterCreated(CefBrowserProxy browser) {
        SwingUtilities.invokeLater(() -> browser.loadURL("http://google.com"));
    }

    @Override
    public void onAfterParentChanged(CefBrowserProxy browser) {
    }

    @Override
    public boolean doClose(CefBrowserProxy browser) {
        return false;
    }

    @Override
    public void onBeforeClose(CefBrowserProxy browser) {
    }
}));

If you run into the issue on #13 you'll need to manually set the zoom level.

@BFergerson BFergerson added this to the v0.4.1 milestone Apr 10, 2020
@BFergerson BFergerson self-assigned this Apr 10, 2020
@BFergerson BFergerson added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Apr 10, 2020
@ara2am
Copy link
Author

ara2am commented Apr 10, 2020

@BFergerson thanks, it works.

Sorry for another question, but is there any way to add listeners for events like onConsoleMessage, onPageStarted/onProgressChanged/onPageFinished in 0.3.3 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants