How to create JBCefBrowser with CefRequestContextHandler?


Faced the following problem:
I need to put some javascript in the page every time the content is loaded in the JBCefBrowser and org.cef.handler.CefRequestHandler#getResourceRequestHandler - helped me a lot with this.

Unfortunately, org.cef.handler.CefRequestHandler is useless in situations where Service Workers are used and we have to use org.cef.handler.CefRequestContextHandler as said in .

So, the problem is - I am unable to find a way to create JBCefBrowser with custom CefRequestContextHandler...

As following from your API the most convenient way to create a JBCefBrowser is something like that:


But there are no parameters/methods to set/add custom CefRequestContextHandler.

Could you please advise how to proceed in this case?

Best regards, Andrew.

Comment actions Permalink

Forwarded, please allow some time for answer. Thanks.

Comment actions Permalink

Hello! Unfortunately current api doesn't allow to create JBCefBrowser with custom CefRequestContextHandler. This possibility will be implemented in 23.1 (

The workaround is to create browser like this:

CefRequestContext context = ...;
JBCefClient client = JBCefApp.getInstance().createClient();
JComponent comp = JBCefOSRHandlerFactory.DEFAULT.createComponent();
CefRenderHandler handler = JBCefOSRHandlerFactory.DEFAULT.createCefRenderHandler(comp);
CefBrowserOsrWithHandler browser =
new CefBrowserOsrWithHandler(client.getCefClient(), "about:blank", context, handler, comp, null, null);
// Call via reflection (because JBCefOsrComponent isn't public):
builder = JBCefBrowser.createBuilder().setOffScreenRendering(true).setClient(client).setCefBrowser(browser);
Comment actions Permalink

Thank you very much I will be waiting for 23.1 )


Please sign in to leave a comment.