Class EngineOptions.Builder
- Enclosing class:
- EngineOptions
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.
-
Method Summary
Modifier and TypeMethodDescriptionaddScheme
(Scheme scheme, InterceptUrlRequestCallback callback) Associates the given URLscheme
with thecallback
, so that all URL requests with the given scheme will be intercepted before they are sent out.Adds the switch to the list of the switches that will be passed to the Chromium process.Allows file access from files for theEngine
instance.build()
Creates anEngineOptions
instance.chromiumDir
(Path chromiumDir) Sets the absolute path to the directory where Chromium binaries are located.Disables Chromium services that cause additional traffic, such as Google Cloud Messaging, Translate Ranker, Extensions Updater, Safe Browsing, etc.Disables DNS quick check.Disables GPU rendering for theEngine
instance.Disables the sandbox for theEngine
instance.Disables the touch popup menu for theEngine
instance.Disables the same-origin policy for theEngine
instance.diskCacheSize
(long diskCacheSize) Sets the disk cache size, in bytes.Allows automatically starting video and audio playbacks.Enables the incognito mode for the default profile of theEngine
instance.Enables media routing for theEngine
instance.Enables the given proprietary feature for theEngine
instance.googleApiKey
(String googleApiKey) Sets the Google API key.googleDefaultClientId
(String googleDefaultClientId) Sets the Google client ID.googleDefaultClientSecret
(String googleDefaultClientSecret) Sets the Google client secret.Sets the Chromium language that is used on the default error pages and the message dialogs.licenseKey
(String licenseKey) Sets the licence key required to perform operations with the engine.passwordStore
(PasswordStore passwordStore) Sets the password store type that specifies which storage backend to use to encrypt cookies on Linux.remoteDebuggingPort
(int remoteDebuggingPort) Sets the remote debugging port.rendererHangTimeout
(Duration timeout) Sets how long the renderer can be unresponsive before it is considered hung.treatInsecureOriginAsSecure
(String... origins) Adds the givenorigins
to the white list.Sets the custom user agent string that is used to override the default user agent for theEngine
.userDataDir
(Path userDataDir) Sets the absolute path to the directory where the user data is stored.
-
Method Details
-
userDataDir
Sets the absolute path to the directory where the user data is stored.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. -
chromiumDir
Sets the absolute path to the directory where Chromium binaries are located.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.
-
licenseKey
Sets the licence key required to perform operations with the engine.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.
- Throws:
IllegalArgumentException
- whenlicenseKey
is empty or blank
-
userAgent
Sets the custom user agent string that is used to override the default user agent for theEngine
.Has the same effect as adding the
--user-agent
switch.- Throws:
IllegalArgumentException
- whenuserAgent
is empty or blank
-
googleApiKey
Sets the Google API key.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.
- Throws:
IllegalArgumentException
- whengoogleApiKey
is empty or blank
-
googleDefaultClientId
Sets the Google client ID.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.
- Throws:
IllegalArgumentException
- whengoogleDefaultClientId
is empty or blank
-
googleDefaultClientSecret
Sets the Google client secret.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.
- Throws:
IllegalArgumentException
- whengoogleDefaultClientSecret
is empty or blank
-
language
Sets the Chromium language that is used on the default error pages and the message dialogs.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. -
remoteDebuggingPort
Sets the remote debugging port.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 anotherBrowser
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.- Throws:
IllegalArgumentException
- whenremoteDebuggingPort
is negative
-
rendererHangTimeout
Sets how long the renderer can be unresponsive before it is considered hung. -
passwordStore
Sets the password store type that specifies which storage backend to use to encrypt cookies on Linux.By default, the encryption storage backend is chosen by the Chromium engine automatically.
Has the same effect as adding the
--password-store
switch. -
diskCacheSize
Sets the disk cache size, in bytes.Has the same effect as adding the
--disk-cache-size
switch.- Throws:
IllegalArgumentException
- whendiskCacheSize
is less or equal than 0
-
disableTouchMenu
Disables the touch popup menu for theEngine
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.- Since:
- 7.1
-
disableDnsQuickCheck
Disables DNS quick check.It turns off WPAD optimization, causing Chromium to wait longer for DNS-based WPAD servers.
- Since:
- 7.29
-
enableIncognito
Enables the incognito mode for the default profile of theEngine
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. -
enableMediaRouting
Enables media routing for theEngine
instance.With enabled media routing the user can use the ChromeCast feature and JavaScript Presentation API.
-
disableSandbox
Disables the sandbox for theEngine
instance.Has the same effect as adding the
--no-sandbox
switch. -
disableWebSecurity
Disables the same-origin policy for theEngine
instance.Has the same effect as adding the
--disable-web-security
switch. -
allowFileAccessFromFiles
Allows file access from files for theEngine
instance.Allows the
file://
URIs to read otherfile://
URIs.Has the same effect as adding the
--allow-file-access-from-files
switch. -
enableAutoplay
Allows automatically starting video and audio playbacks.Has the same effect as adding the
--autoplay-policy=no-user-gesture-required
switch. -
disableGpu
Disables GPU rendering for theEngine
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. -
treatInsecureOriginAsSecure
Adds the givenorigins
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.- Since:
- 7.2
-
addSwitch
Adds the switch to the list of the switches that will be passed to the Chromium process.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.- Throws:
IllegalArgumentException
- when thecommandLineSwitch
is empty or blank
-
enableProprietaryFeature
Enables the given proprietary feature for theEngine
instance.By default, all the proprietary features are disabled.
- Since:
- 7.4
- See Also:
-
disableChromiumTraffic
Disables Chromium services that cause additional traffic, such as Google Cloud Messaging, Translate Ranker, Extensions Updater, Safe Browsing, etc. These services are related to the features that are not currently supported in JxBrowser. This option does not affect the supported features, such as SpellChecker or Widevine.By default, Chromium services that cause additional traffic are enabled
- Since:
- 7.10
-
addScheme
Associates the given URLscheme
with thecallback
, 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
- Parameters:
scheme
- the URL scheme of a URL request to interceptcallback
- the callback that will be invoked to intercept URL requests with the given scheme- Throws:
IllegalArgumentException
- when the givenscheme
cannot be intercepted- Since:
- 7.13
-
build
Creates anEngineOptions
instance.
-