Class EngineOptions.Builder

java.lang.Object
com.teamdev.jxbrowser.engine.EngineOptions.Builder
Enclosing class:
EngineOptions

public static final class EngineOptions.Builder extends Object
A builder class to construct engine options.

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 Details

    • userDataDir

      public EngineOptions.Builder userDataDir(Path 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

      public EngineOptions.Builder chromiumDir(Path 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

      public EngineOptions.Builder licenseKey(String 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 - when licenseKey is empty or blank
    • userAgent

      public EngineOptions.Builder userAgent(String userAgent)
      Sets the custom user agent string that is used to override the default user agent for the Engine.

      Has the same effect as adding the --user-agent switch.

      Throws:
      IllegalArgumentException - when userAgent is empty or blank
    • googleApiKey

      public EngineOptions.Builder googleApiKey(String 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 - when googleApiKey is empty or blank
    • googleDefaultClientId

      public EngineOptions.Builder googleDefaultClientId(String 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 - when googleDefaultClientId is empty or blank
    • googleDefaultClientSecret

      public EngineOptions.Builder googleDefaultClientSecret(String 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 - when googleDefaultClientSecret is empty or blank
    • language

      public EngineOptions.Builder language(Language 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

      public EngineOptions.Builder remoteDebuggingPort(int 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 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.

      Throws:
      IllegalArgumentException - when remoteDebuggingPort is negative
    • rendererHangTimeout

      public EngineOptions.Builder rendererHangTimeout(Duration timeout)
      Sets how long the renderer can be unresponsive before it is considered hung.
    • passwordStore

      public EngineOptions.Builder passwordStore(PasswordStore 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

      public EngineOptions.Builder diskCacheSize(long diskCacheSize)
      Sets the disk cache size, in bytes.

      Has the same effect as adding the --disk-cache-size switch.

      Throws:
      IllegalArgumentException - when diskCacheSize is less or equal than 0
    • disableTouchMenu

      public EngineOptions.Builder disableTouchMenu()
      Disables the touch popup menu for the 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.

      Since:
      7.1
    • disableDnsQuickCheck

      public EngineOptions.Builder disableDnsQuickCheck()
      Disables DNS quick check.

      It turns off WPAD optimization, causing Chromium to wait longer for DNS-based WPAD servers.

      Since:
      7.29
    • enableIncognito

      public EngineOptions.Builder enableIncognito()
      Enables the incognito mode for the default profile of the 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.

    • enableMediaRouting

      public EngineOptions.Builder enableMediaRouting()
      Enables media routing for the Engine instance.

      With enabled media routing the user can use the ChromeCast feature and JavaScript Presentation API.

      Since:
      7.29
      See Also:
    • disableSandbox

      public EngineOptions.Builder disableSandbox()
      Disables the sandbox for the Engine instance.

      Has the same effect as adding the --no-sandbox switch.

    • disableWebSecurity

      public EngineOptions.Builder disableWebSecurity()
      Disables the same-origin policy for the Engine instance.

      Has the same effect as adding the --disable-web-security switch.

    • allowFileAccessFromFiles

      public EngineOptions.Builder allowFileAccessFromFiles()
      Allows file access from files for the Engine instance.

      Allows the file:// URIs to read other file:// URIs.

      Has the same effect as adding the --allow-file-access-from-files switch.

    • enableAutoplay

      public EngineOptions.Builder enableAutoplay()
      Allows automatically starting video and audio playbacks.

      Has the same effect as adding the --autoplay-policy=no-user-gesture-required switch.

    • disableGpu

      public EngineOptions.Builder disableGpu()
      Disables GPU rendering for the 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.

    • treatInsecureOriginAsSecure

      public EngineOptions.Builder treatInsecureOriginAsSecure(String... origins)
      Adds the given 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.

      Since:
      7.2
    • addSwitch

      public EngineOptions.Builder addSwitch(String commandLineSwitch)
      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 the commandLineSwitch is empty or blank
    • enableProprietaryFeature

      public EngineOptions.Builder enableProprietaryFeature(ProprietaryFeature feature)
      Enables the given proprietary feature for the Engine instance.

      By default, all the proprietary features are disabled.

      Since:
      7.4
      See Also:
    • disableChromiumTraffic

      public EngineOptions.Builder 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

      public 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.

      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 intercept
      callback - the callback that will be invoked to intercept URL requests with the given scheme
      Throws:
      IllegalArgumentException - when the given scheme cannot be intercepted
      Since:
      7.13
    • build

      public EngineOptions build()
      Creates an EngineOptions instance.