public static final class EngineOptions.Builder
extends java.lang.Object
Builders are created by invoking EngineOptions.newBuilder(com.teamdev.jxbrowser.engine.RenderingMode)
. Each of the setter methods modifies
the state of the builder and returns the same instance. Builders are not thread-safe and
should not be used concurrently from multiple threads without external synchronization.
Modifier and Type | Method and Description |
---|---|
EngineOptions.Builder |
addScheme(Scheme scheme,
InterceptUrlRequestCallback callback)
Associates the given URL
scheme with the callback , so that all URL
requests with the given scheme will be intercepted before they are sent out. |
EngineOptions.Builder |
addSwitch(java.lang.String commandLineSwitch)
Adds the switch to the list of the switches that will be passed to the Chromium process.
|
EngineOptions.Builder |
allowFileAccessFromFiles()
Allows file access from files for the
Engine instance. |
EngineOptions |
build()
Creates an
EngineOptions instance. |
EngineOptions.Builder |
chromiumDir(java.nio.file.Path chromiumDir)
Sets the absolute path to the directory where Chromium binaries are located.
|
EngineOptions.Builder |
disableChromiumTraffic()
Disables Chromium services that cause additional traffic, such as Google Cloud Messaging,
Translate Ranker, Extensions Updater, Safe Browsing, etc.
|
EngineOptions.Builder |
disableDnsQuickCheck()
Disables DNS quick check.
|
EngineOptions.Builder |
disableGpu()
Disables GPU rendering for the
Engine instance. |
EngineOptions.Builder |
disableSandbox()
Disables the sandbox for the
Engine instance. |
EngineOptions.Builder |
disableTouchMenu()
Disables the touch popup menu for the
Engine instance. |
EngineOptions.Builder |
disableWebSecurity()
Disables the same-origin policy for the
Engine instance. |
EngineOptions.Builder |
diskCacheSize(long diskCacheSize)
Sets the disk cache size, in bytes.
|
EngineOptions.Builder |
enableAutoplay()
Allows automatically starting video and audio playbacks.
|
EngineOptions.Builder |
enableIncognito()
Enables the incognito mode for the default profile of the
Engine instance. |
EngineOptions.Builder |
enableMediaRouting()
Enables media routing for the
Engine instance. |
EngineOptions.Builder |
enableProprietaryFeature(ProprietaryFeature feature)
Enables the given proprietary feature for the
Engine instance. |
EngineOptions.Builder |
googleApiKey(java.lang.String googleApiKey)
Sets the Google API key.
|
EngineOptions.Builder |
googleDefaultClientId(java.lang.String googleDefaultClientId)
Sets the Google client ID.
|
EngineOptions.Builder |
googleDefaultClientSecret(java.lang.String googleDefaultClientSecret)
Sets the Google client secret.
|
EngineOptions.Builder |
language(Language language)
Sets the Chromium language that is used on the default error pages and the message
dialogs.
|
EngineOptions.Builder |
licenseKey(java.lang.String licenseKey)
Sets the licence key required to perform operations with the engine.
|
EngineOptions.Builder |
passwordStore(PasswordStore passwordStore)
Sets the password store type that specifies which storage backend to use to encrypt
cookies on Linux.
|
EngineOptions.Builder |
remoteDebuggingPort(int remoteDebuggingPort)
Sets the remote debugging port.
|
EngineOptions.Builder |
rendererHangTimeout(java.time.Duration timeout)
Sets how long the renderer can be unresponsive before it is considered hung.
|
EngineOptions.Builder |
treatInsecureOriginAsSecure(java.lang.String... origins)
Adds the given
origins to the white list. |
EngineOptions.Builder |
userAgent(java.lang.String userAgent)
Sets the custom user agent string that is used to override the default user agent for the
Engine . |
EngineOptions.Builder |
userDataDir(java.nio.file.Path userDataDir)
Sets the absolute path to the directory where the user data is stored.
|
public EngineOptions.Builder userDataDir(java.nio.file.Path userDataDir)
If the directory with the given path does not exist, then the library will create this directory.
Types of stored data are cache, cookies, history, GPU cache, local storage, visited links, web data, spell checking dictionary files, etc.
Important: the user data directory cannot be used at the same time by multiple
Engine
instances running in a single or different applications.
public EngineOptions.Builder chromiumDir(java.nio.file.Path chromiumDir)
If the directory contains the Chromium binaries, the library will check them and make sure that they are compatible with the current library version. If the directory does not contain the Chromium binaries, or the binaries are not compatible with the current library version, the library will search for the binaries inside the JAR files from the application classpath and extract them into the given directory programmatically. It might take some time to extract the Chromium binaries from a JAR archive. The time depends on the hardware (CPU and SSD/HDD) performance.
public EngineOptions.Builder licenseKey(java.lang.String licenseKey)
The license key can be set using the "jxbrowser.license.key" system property. This method allows you to override the license key specified in the system property with the given value.
java.lang.IllegalArgumentException
- when licenseKey
is empty or blankpublic EngineOptions.Builder userAgent(java.lang.String userAgent)
Engine
.
Has the same effect as adding the --user-agent
switch.
java.lang.IllegalArgumentException
- when userAgent
is empty or blankpublic EngineOptions.Builder googleApiKey(java.lang.String googleApiKey)
Some Chromium features such as Geolocation, Spelling, Speech, etc. use Google APIs, and to access those APIs, an API Key, OAuth 2.0 client ID, and client secret are required. Setting up API keys is optional. If you do not do it, the specific APIs using Google services will not work.
java.lang.IllegalArgumentException
- when googleApiKey
is empty or blankpublic EngineOptions.Builder googleDefaultClientId(java.lang.String googleDefaultClientId)
Some Chromium features such as Geolocation, Spelling, Speech, etc. use Google APIs, and to access those APIs, an API Key, OAuth 2.0 client ID, and client secret are required. Setting up API keys is optional. If you do not do it, the specific APIs using Google services will not work.
java.lang.IllegalArgumentException
- when googleDefaultClientId
is empty or blankpublic EngineOptions.Builder googleDefaultClientSecret(java.lang.String googleDefaultClientSecret)
Some Chromium features such as Geolocation, Spelling, Speech, etc. use Google APIs, and to access those APIs, an API Key, OAuth 2.0 client ID, and client secret are required. Setting up API keys is optional. If you do not do it, the specific APIs using Google services will not work.
java.lang.IllegalArgumentException
- when googleDefaultClientSecret
is
empty or blankpublic EngineOptions.Builder language(Language language)
By default, the language is dynamically configured according to the default locale of the application. If the list of supported languages does not contain the language obtained from the application locale, then the US English language is used. The current option allows you to override the default behavior and configure the Chromium engine with the given language.
Has the same effect as adding the --lang
switch.
public EngineOptions.Builder remoteDebuggingPort(int remoteDebuggingPort)
This option enables remote debugging over HTTP at the specific port. When remote
debugging is enabled, you can navigate to the http://localhost:<port>
address
from another Browser
instance or from the Google Chrome browser and debug the web
pages that are currently loaded using Chrome DevTools. If you use the Google Chrome
browser for remote debugging, its version must be equal to the Chromium engine version
that is used in JxBrowser.
Has the same effect as adding the --remote-debugging-port
switch.
java.lang.IllegalArgumentException
- when remoteDebuggingPort
is negativepublic EngineOptions.Builder rendererHangTimeout(java.time.Duration timeout)
public EngineOptions.Builder passwordStore(PasswordStore passwordStore)
By default, the encryption storage backend is chosen by the Chromium engine automatically.
Has the same effect as adding the --password-store
switch.
public EngineOptions.Builder diskCacheSize(long diskCacheSize)
Has the same effect as adding the --disk-cache-size
switch.
java.lang.IllegalArgumentException
- when diskCacheSize
is <= 0public EngineOptions.Builder disableTouchMenu()
Engine
instance.
By default, when user performs long press on the touch screen the popup menu is displayed. This method prevents showing of this menu.
Has the same effect as adding the --disable-touch-menu
switch.
public EngineOptions.Builder disableDnsQuickCheck()
It turns off WPAD optimization, causing Chromium to wait longer for DNS-based WPAD servers.
public EngineOptions.Builder enableIncognito()
Engine
instance.
When using this option the default profile created on the engine start will be incognito. The option affects the type of the default profile only.
In the incognito mode the user data such as browsing history, cookies, site data, and
the information entered in forms are stored in memory and released once you close the
Engine
.
Has the same effect as adding the --incognito
switch.
public EngineOptions.Builder enableMediaRouting()
Engine
instance.
With enabled media routing the user can use the ChromeCast feature and JavaScript Presentation API.
public EngineOptions.Builder disableSandbox()
Engine
instance.
Has the same effect as adding the --no-sandbox
switch.
public EngineOptions.Builder disableWebSecurity()
Engine
instance.
Has the same effect as adding the --disable-web-security
switch.
public EngineOptions.Builder allowFileAccessFromFiles()
Engine
instance.
Allows the file://
URIs to read other file://
URIs.
Has the same effect as adding the --allow-file-access-from-files
switch.
public EngineOptions.Builder enableAutoplay()
Has the same effect as adding the --autoplay-policy=no-user-gesture-required
switch.
public EngineOptions.Builder disableGpu()
Engine
instance.
If software renderer is not in place, then the GPU process won't launch.
Has the same effect as adding the --disable-gpu
switch.
public EngineOptions.Builder treatInsecureOriginAsSecure(java.lang.String... origins)
origins
to the white list. These origins will be treated as
secure origins.
Each origin passed to this method should be an origin or hostname pattern up to eTLD+1. For example, the list may contain "http://foo.com", "http://foo.com:8000", "*.foo.com", "*.foo.*.bar.com", and "http://*.foo.bar.com", but not "*.co.uk", "*.com", or "test.*.com". Hostname patterns must contain a wildcard somewhere (so "test.com" is not a valid pattern) and wildcards can only replace full components ("test*.foo.com" is not valid).
Has the same effect as adding the --unsafely-treat-insecure-origin-as-secure
switch.
public EngineOptions.Builder addSwitch(java.lang.String commandLineSwitch)
Important For advanced usage only. The library does not support all the possible Chromium switches, so there is no guarantee that the passed switches will work. All the supported switches can be set through the corresponding methods of this builder. Switches added using this method will overwrite the corresponding options configured through the methods of this builder.
For example, if you configure the remote debugging port using the remoteDebuggingPort(int)
method and then add the --remote-debugging-port
switch
using this method, the port from the switch will be used.
java.lang.IllegalArgumentException
- when the commandLineSwitch
is empty or blankpublic EngineOptions.Builder enableProprietaryFeature(ProprietaryFeature feature)
Engine
instance.
By default, all the proprietary features are disabled.
ProprietaryFeature
public EngineOptions.Builder disableChromiumTraffic()
By default, Chromium services that cause additional traffic are enabled
public EngineOptions.Builder addScheme(Scheme scheme, InterceptUrlRequestCallback callback)
scheme
with the callback
, so that all URL
requests with the given scheme will be intercepted before they are sent out.
Each scheme can be treated by Chromium as:
Standard: the schemes in the standard format described in RFC 3986 Section 3. The syntax for standard scheme URLs must be in the following form:
[scheme]://[username]:[password]@[host]:[port]/[path]
Note: the non-standard URLs with the standard scheme will be canonicalized to "scheme://host/path". For example, "scheme:host/path" will be canonicalized to "scheme://host/path".
Referrer: the schemes that are allowed for referrers.
Secure: the schemes that are treated with the same security rules as those applied to "https" URLs.
Local: the schemes that normal pages cannot link to or access (i.e. with the
same security rules as those applied to "file" URLs). Normal pages cannot link to or
access local URLs. Also, by default, local URLs can only perform XMLHttpRequest
calls to the same URL (origin + path) that originated the request.
No Access: the schemes that cause pages loaded with them to not have access to pages loaded with any other URL scheme.
CORS Enabled: the schemes that can sent CORS requests.
Web Storage: the schemes that can be used by web pages to store data using local storage.
CSP Bypassing: the schemes that can bypass the Content-Security-Policy (CSP) checks.
For example, HTTPS
is treated as standard, referrer, secure, CORS enabled,
and web storage.
Not any scheme can be added and intercepted. The following schemes cannot be
intercepted, so you will get IllegalArgumentException
if you try to add them:
about
blob
content
cid
data
file
filesystem
ftp
javascript
mailto
quic-transport
tel
ws
wss
devtools
chrome
chrome-error
chrome-distiller
chrome-untrusted
chrome-guest
chrome-search
chrome-extension
chrome-native
view-source
externalfile
googlechrome
scheme
- the URL scheme of a URL request to interceptcallback
- the callback that will be invoked to intercept URL requests with the
given schemejava.lang.IllegalArgumentException
- when the given scheme
cannot be interceptedpublic EngineOptions build()
EngineOptions
instance.