In JxBrowser 7.12 the Chromium engine has been upgraded to version 84. This Chromium version has several breaking changes in the source code that affect the public API of JxBrowser. In this migration guide we describe what API has been removed in 7.12 and what alternatives you should use instead.

Network

Overriding HTTP Request Headers

v7.11

The BeforeSendHeadersCallback and BeforeSendProxyHeadersCallback callbacks have been removed in Chromium 84.

network.set(BeforeSendHeadersCallback.class, params -> 
        BeforeSendHeadersCallback.Response.override(modifiedHeaders));
network.set(BeforeSendProxyHeadersCallback.class, params ->
        BeforeSendProxyHeadersCallback.Response.override(modifiedHeaders));

v7.12

To override HTTP headers before they will be sent to a web server use the following API:

network.set(BeforeStartTransactionCallback.class, params -> 
    BeforeStartTransactionCallback.Response.override(modifiedHeaders));

Filtering Resources

The LoadResourceCallback callback have been removed in Chromium 84.

v7.11

network.set(LoadResourceCallback.class, params -> {
    if (params.resourceType() == ResourceType.IMAGE) {
        return LoadResourceCallback.Response.cancel();
    }
    return LoadResourceCallback.Response.load();
});

v7.12

Use the BeforeUrlRequestCallback callback to filter resources as shown below:

network.set(BeforeUrlRequestCallback.class, params -> {
    if (params.urlRequest().resourceType() == ResourceType.IMAGE) {
        return BeforeUrlRequestCallback.Response.cancel();
    }
    return BeforeUrlRequestCallback.Response.proceed();
});

Cache

v7.11

The deprecated HttpCache.clearDiskCache(Runnable) method has been removed:

httpCache.clearDiskCache(() -> {
    // HTTP cache has been cleared.
});

v7.12

Use the following API instead:

CompletableFuture<Void> future = httpCache.clear();

User Input

Mouse Wheel

v7.11

The following deprecated com.teamdev.jxbrowser.ui.event.MouseWheel methods has been removed:

  • isHorizontalScroll()
  • scrollbarPixelsPerLine()
  • unitsToScroll()

v7.12

Use the deltaX() and deltaY() methods instead.

DOM

Keyboard Events

The way to access the key code in com.teamdev.jxbrowser.dom.event.KeyEvent has been changed. As a result, the useless com.teamdev.jxbrowser.dom.event.KeyEvent.keyCode() method has been removed.

v7.11

To access the key code of the DOM KeyEvent you use the following API:

document.addEventListener(EventType.KEY_PRESS, event -> {
    if (event instanceof KeyEvent) {
        KeyEvent keyEvent = (KeyEvent) event;
        System.out.println("DOM KeyEvent: keyCode=" + keyEvent.keyCode());
    }
}, false);

This approach has several limitations: no way to get the character of the presses key in the currently selected language. You can only get the key code as a predefined enum value.

v7.12

In this version we improved this functionality, so now it works close to how it works in the DOM API:

document.addEventListener(EventType.KEY_PRESS, event -> {
    if (event instanceof KeyEvent) {
        KeyEvent keyEvent = (KeyEvent) event;
        DomKeyCode keyCode = keyEvent.domKeyCode();
        String character = keyEvent.character();
        System.out.println("DOM KeyEvent: keyCode=" + keyCode  + ", character=" + character);
    }
}, false);

Now you can get the expected key code and a string representation of the character of the presses key in the currently selected language.

JavaScript-Java Bridge API

Accessing Java public static methods from JavaScript is forbidden now.

JavaScript-Java Bridge allows injecting Java objects into JavaScript and working with them through Java references. Working with the static methods through a Java object reference is not recommended and error prone way.

Loading URL

v7.11

The following deprecated Navigation methods have been removed:

  • loadUrlAndWait(String, Timestamp)
  • loadUrlAndWait(LoadUrlParams, Timestamp)

v7.12

Use the following methods instead:

  • loadUrlAndWait(String url, Duration timeout)
  • loadUrlAndWait(LoadUrlParams params, Duration timeout)

Default Timeout

v7.11

The deprecated Navigation.DEFAULT_TIMEOUT_IN_SECONDS static field has been removed.

v7.12

Use the following alternative instead:

Duration timeoutInSeconds = Navigation.defaultTimeoutInSeconds();

Removed API

The following classes and methods have been removed because the corresponding functionality in Chromium 84 does not exist anymore and no alternatives were given:

  • The com.teamdev.jxbrowser.navigation.event.FrameLoadFailed.errorDescription() method has been removed without any alternative.
  • The com.teamdev.jxbrowser.net.event.RequestCompleted.isStarted() method has been removed because now the URL Request cannot be completed if it hasn’t been started. So, there’s no sense in this method because it always returns true.
  • The deprecated Timestamp.MILLIS_PER_SECOND static field has been removed.
Go Top