Interface Engine
- All Superinterfaces:
AutoCloseable
,Closeable
,Observable<EngineEvent>
To perform operations with the engine, a license key is required. The license key represents
a string that can be set via the "jxbrowser.license.key" system property or individually for
every Engine
using the EngineOptions.Builder.licenseKey(String)
method. If you
set the license key via the system property, then please make sure that you set it before
creating an Engine
instance.
The Chromium engine is running in a separate native process. Communication between the native and Java process is done through the Inter-Process Communication (IPC) layer that allows transferring data between two processes on a local machine.
The native process allocates memory and system resources that must be released. So, when the
engine is no longer needed, it must be closed through the Closeable.close()
method to shutdown
the native process and free all the allocated memory and system resources. For example:
Engine engine = Engine.newInstance(engineOptions); ... engine.close();
Any attempt to use an already closed engine will lead to the IllegalStateException
.
To get notifications that the Engine
instance has been closed subscribe to the
following event:
engine.on(EngineClosed.class, event -> {
// The engine has been closed.
});
To get notifications that the Engine
instance has been unexpectedly terminated use:
engine.on(EngineCrashed.class, event -> {
// The engine has been unexpectedly terminated.
});
-
Method Summary
Modifier and TypeMethodDescriptionbrowsers()
Returns an immutable list of aliveBrowser
instances including child popup browsers for the default profile.Returns the cookie store that allows managing cookies.Returns a service that allows managing downloads.Returns a service for working with HTTP authentication cache.Returns a service for working with HTTP cache.Returns a service that allows managing media stream devices.network()
Returns a service that allows working with network.Creates a newBrowser
instance under the default profile and navigates it to the "about:blank" web page within theNavigation.defaultTimeout()
.static Engine
newInstance
(EngineOptions options) Initializes and runs the Chromium engine with the givenoptions
.static Engine
newInstance
(RenderingMode renderingMode) Initializes and runs the Chromium engine in the givenrenderingMode
.options()
Returns the options the current engine was initialized with.Returns a service that allows managing permissions.plugins()
Returns a service that allows configuring plugins.profiles()
Returns a service for managing profiles.proxy()
Returns a service that allows working with proxy.Returns a service that allows working with spell checking functionality.Returns a service that allows working with zoom.Methods inherited from interface com.teamdev.jxbrowser.event.Observable
on
-
Method Details
-
newInstance
Initializes and runs the Chromium engine in the givenrenderingMode
.Depending on the hardware performance, the initialization process might take several seconds. So, do not call this method in the application UI thread.
The method performs the following actions:
- Checks the environment and makes sure that it is supported.
- Locates the Chromium binaries and extracts them if it is necessary.
- Runs the main native process and initializes the Chromium engine.
- Setup IPC connection between Java and the main native process.
- Parameters:
renderingMode
- the rendering mode indicating how the content of the web pages will be rendered- Returns:
- a new instance of the
Engine
- Throws:
EnvironmentException
- when the current environment is not supportedUserDataDirectoryCreationException
- when the given user data directory does not exist and cannot be createdUserDataDirectoryAlreadyInUseException
- when the given user data directory is already in use.IpcSetupFailureException
- when Inter-Process Communication (IPC) setup has been failedChromiumProcessStartupFailureException
- when startup of the Chromium process has been failedNoLicenseException
- when no license foundInvalidLicenseException
- when no valid license foundChromiumBinariesDeliveryException
- when the verification of the Chromium binary files has failed and the binaries cannot be extracted from the resourcesMissingDependencyException
- when Chromium fails to find the required system libraries. This exception can only be thrown on Linux
-
newInstance
Initializes and runs the Chromium engine with the givenoptions
.Depending on the hardware performance, the initialization process might take several seconds. So, do not call this method in the application UI thread.
The method performs the following actions:
- Checks the environment and makes sure that it is supported.
- Locates the Chromium binaries and extracts them if it is necessary.
- Runs the main native process and initializes the Chromium engine.
- Setup IPC connection between Java and the main native process.
- Parameters:
options
- the engine options- Returns:
- a new instance of the
Engine
- Throws:
EnvironmentException
- when the current environment is not supportedUserDataDirectoryCreationException
- when the given user data directory does not exist and cannot be createdUserDataDirectoryAlreadyInUseException
- when the given user data directory is already in use.IpcSetupFailureException
- when Inter-Process Communication (IPC) setup has been failedChromiumProcessStartupFailureException
- when startup of the Chromium process has been failedNoLicenseException
- when no license foundInvalidLicenseException
- when no valid license foundChromiumBinariesDeliveryException
- when the verification of the Chromium binary files has failed and the binaries cannot be extracted from the resourcesMissingDependencyException
- when Chromium fails to find the required system libraries. This exception can only be thrown on Linux
-
options
EngineOptions options()Returns the options the current engine was initialized with. -
newBrowser
Browser newBrowser()Creates a newBrowser
instance under the default profile and navigates it to the "about:blank" web page within theNavigation.defaultTimeout()
.- Returns:
- a new
Browser
instance - Throws:
TimeoutException
- when the engine failed to create a browser instance within the timeoutNavigationException
- when the navigation to the "about:blank" has failedObjectClosedException
- when the engine is already closed
-
browsers
Returns an immutable list of aliveBrowser
instances including child popup browsers for the default profile.Returns an empty list if the profile does not have any alive
Browser
.- Returns:
- the list of alive
Browser
instances for the default profile of this engine
-
zoomLevels
ZoomLevels zoomLevels()Returns a service that allows working with zoom.- Implementation Note:
- The service belongs to the default profile.
-
proxy
Proxy proxy()Returns a service that allows working with proxy.- Implementation Note:
- The service belongs to the default profile.
-
network
Network network()Returns a service that allows working with network.- Implementation Note:
- The service belongs to the default profile.
-
spellChecker
SpellChecker spellChecker()Returns a service that allows working with spell checking functionality.- Implementation Note:
- The service belongs to the default profile.
-
cookieStore
CookieStore cookieStore()Returns the cookie store that allows managing cookies.- Implementation Note:
- The service belongs to the default profile.
-
httpCache
HttpCache httpCache()Returns a service for working with HTTP cache.- Implementation Note:
- The service belongs to the default profile.
-
httpAuthCache
HttpAuthCache httpAuthCache()Returns a service for working with HTTP authentication cache.- Implementation Note:
- The service belongs to the default profile.
-
mediaDevices
MediaDevices mediaDevices()Returns a service that allows managing media stream devices. -
plugins
Plugins plugins()Returns a service that allows configuring plugins.- Implementation Note:
- The service belongs to the default profile.
-
downloads
Downloads downloads()Returns a service that allows managing downloads.- Implementation Note:
- The service belongs to the default profile.
-
permissions
Permissions permissions()Returns a service that allows managing permissions.- Implementation Note:
- The service belongs to the default profile.
-
profiles
Profiles profiles()Returns a service for managing profiles.
-