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 URLschemewith 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 theEngineinstance.build()Creates anEngineOptionsinstance.chromiumDir(Path chromiumDir) Sets the absolute path to the directory where Chromium binaries are located.Indicates whether the DNS over HTTPS (DoH) protocol is disabled.Disables DNS quick check.Disables GPU rendering for theEngineinstance.Disables the sandbox for theEngineinstance.Disables the touch popup menu for theEngineinstance.Disables the same-origin policy for theEngineinstance.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 theEngineinstance.Enables media routing for theEngineinstance.Enables the given proprietary feature for theEngineinstance.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.Sets the time zone that will be used instead of the host operating system time zone.treatInsecureOriginAsSecure(String... origins) Adds the givenoriginsto 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
Engineinstances 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- whenlicenseKeyis 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-agentswitch.- Throws:
IllegalArgumentException- whenuserAgentis 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- whengoogleApiKeyis 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- whengoogleDefaultClientIdis 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- whengoogleDefaultClientSecretis 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
--langswitch. -
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 anotherBrowserinstance 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-portswitch.- Throws:
IllegalArgumentException- whenremoteDebuggingPortis 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-storeswitch. -
diskCacheSize
Sets the disk cache size, in bytes.Has the same effect as adding the
--disk-cache-sizeswitch.- Throws:
IllegalArgumentException- whendiskCacheSizeis less or equal than 0
-
disableTouchMenu
Disables the touch popup menu for theEngineinstance.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-menuswitch.- 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
-
timeZone
Sets the time zone that will be used instead of the host operating system time zone.- Parameters:
zoneId- the time zone that will be used- Since:
- 8.12.0
-
enableIncognito
Enables the incognito mode for the default profile of theEngineinstance.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
--incognitoswitch. -
enableMediaRouting
Enables media routing for theEngineinstance.With enabled media routing the user can use the ChromeCast feature and JavaScript Presentation API.
-
disableSandbox
Disables the sandbox for theEngineinstance.Has the same effect as adding the
--no-sandboxswitch. -
disableWebSecurity
Disables the same-origin policy for theEngineinstance.Has the same effect as adding the
--disable-web-securityswitch. -
allowFileAccessFromFiles
Allows file access from files for theEngineinstance.Allows the
file://URIs to read otherfile://URIs.Has the same effect as adding the
--allow-file-access-from-filesswitch. -
enableAutoplay
Allows automatically starting video and audio playbacks.Has the same effect as adding the
--autoplay-policy=no-user-gesture-requiredswitch. -
disableGpu
Disables GPU rendering for theEngineinstance.If software renderer is not in place, then the GPU process won't launch.
Has the same effect as adding the
--disable-gpuswitch. -
treatInsecureOriginAsSecure
Adds the givenoriginsto 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-secureswitch.- 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-portswitch using this method, the port from the switch will be used.- Throws:
IllegalArgumentException- when thecommandLineSwitchis empty or blank
-
enableProprietaryFeature
Enables the given proprietary feature for theEngineinstance.By default, all the proprietary features are disabled.
- Since:
- 7.4
- See Also:
-
disableDnsOverHttps
Indicates whether the DNS over HTTPS (DoH) protocol is disabled.By default, Chromium uses DoH as the primary DNS resolve protocol. Initially, Chromium checks whether the system DNS provider support DoH and tries to recognize it. If the system DNS is configured to use Google Public DNS or another recognized provider that supports DoH, Chromium will automatically switch to that provider’s DoH service.
When disabled, Chromium uses the unencrypted system DNS over UDP or TCP as configured by the operating system for DNS resolution.
- Since:
- 8.2.0
-
addScheme
Associates the given URLschemewith 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
XMLHttpRequestcalls 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,
HTTPSis 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
IllegalArgumentExceptionif you try to add them:aboutblobcontentciddatafilefilesystemftpjavascriptmailtoquic-transporttelwswssdevtoolschromechrome-errorchrome-distillerchrome-untrustedchrome-guestchrome-searchchrome-extensionchrome-nativeview-sourceexternalfilegooglechrome
- 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 givenschemecannot be intercepted- Since:
- 7.13
-
build
Creates anEngineOptionsinstance.
-