From 7.11 to 7.12
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));
network.set(BeforeSendHeadersCallback::class.java,
BeforeSendHeadersCallback { params ->
BeforeSendHeadersCallback.Response.override(modifiedHeaders)
}
)
network.set(BeforeSendProxyHeadersCallback::class.java,
BeforeSendProxyHeadersCallback { 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));
network.set(BeforeStartTransactionCallback::class.java,
BeforeStartTransactionCallback { 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();
});
network.set(LoadResourceCallback::class.java,
LoadResourceCallback { params ->
if (params.resourceType() == ResourceType.IMAGE) {
LoadResourceCallback.Response.cancel()
} else {
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();
});
network.set(BeforeUrlRequestCallback::class.java,
BeforeUrlRequestCallback { params ->
if (params.urlRequest().resourceType() == ResourceType.IMAGE) {
BeforeUrlRequestCallback.Response.cancel()
} else {
BeforeUrlRequestCallback.Response.proceed()
}
}
)
Cache
v7.11
The deprecated HttpCache.clearDiskCache(Runnable)
method has been removed:
httpCache.clearDiskCache(() -> {
// HTTP cache has been cleared.
});
httpCache.clearDiskCache {
// HTTP cache has been cleared.
}
v7.12
Use the following API instead:
CompletableFuture<Void> future = httpCache.clear();
val future: CompletableFuture<Void> = 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);
document.addEventListener(EventType.KEY_PRESS, { event ->
if (event is KeyEvent) {
println("DOM KeyEvent: keyCode=${event.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);
document.addEventListener(EventType.KEY_PRESS, { event ->
if (event is KeyEvent) {
val keyCode = event.keyCode
val character = event.keyChar
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.
Navigation
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 timeout = Navigation.defaultTimeout();
val timeout: Duration = Navigation.defaultTimeout()
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 returnstrue
. - The deprecated
Timestamp.MILLIS_PER_SECOND
static field has been removed.