com.equo.chromium
Interface ChromiumBrowser
-
public interface ChromiumBrowser
It provides the methods for the creation of the different types of browsers SWT, Swing, Standalone, Windowless as well as the complementary methods for their management. All methods of this interface can be called from any thread unless otherwise indicated by the specific method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static interface
ChromiumBrowser.ConsoleListener
Listener to receive console events from the browser.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method and Description void
addConsoleListener(ChromiumBrowser.ConsoleListener listener)
Adds a listener to receive console events from the browser.boolean
canGoBack()
Checks whether there is a previous page to navigate back to in the browsing history.boolean
canGoForward()
Checks whether there is a subsequent page to navigate forward to in the browsing history.CompletableFuture<byte[]>
captureScreenshot()
Capture screenshot from browser.CompletableFuture<byte[]>
captureScreenshot(int x, int y, int width, int height, int scale)
Capture screenshots of a specific area.static boolean
clearCookies(String urlPattern, String namePattern)
/** Delete cookies matching the url and name regex patterns.boolean
close()
static CompatibleWithHost
compatibleWithHost()
Create a CompatibleWithHost constructor.static void
earlyInit()
Early load and initialize the Equo Chromium engine and libraries.void
executeJavacript(String script)
Deprecated.Executes JavaScript code within the context of the browser window. Use executeJavaScript(String) instead.void
executeJavaScript(String script)
Executes JavaScript code within the context of the browser window.void
find(String search, boolean forward, boolean matchCase)
Finds text within the browser window based on the specified search criteria.static Collection<ChromiumBrowser>
getAllBrowsers()
Retrieves a collection of all ChromiumBrowser instances currently active within the application.List<Object>
getErrors()
Gets all errors when the rendering process terminates unexpectedly.com.equo.chromium.Storage
getLocalStorage()
Returns an instance of LocalStorage.com.equo.chromium.Storage
getSessionStorage()
Returns an instance of SessionStorage.Object
getUIComponent()
Gets the Composite or Component UI object, depending on the current toolkit.String
getUrl()
Gets the current url.double
getZoom()
Get the current zoom level.void
goBack()
Loads the previous location in the back-forward list.void
goForward()
Loads the next location in the back-forward list.void
ignoreCertificateErrors(boolean enable)
Ignore certificate errors in the browser.boolean
isClosed()
Checks if the browser has been closed.CompletableFuture<Boolean>
isCreated()
Checks whether the browser has been created.boolean
isLoading()
Checks whether the browser is currently loading a page.CompletableFuture<Boolean>
printToPdf(String path)
Print the current browser contents as a PDF.CompletableFuture<Boolean>
printToPdf(String path, PdfPrintSettings settings)
Print the current browser contents as a PDF.void
reload()
Reloads the currently loaded web page.void
removeConsoleListener(ChromiumBrowser.ConsoleListener listener)
Removes a previously added console listener from the browser.boolean
setText(String html)
Sets the text content of the browser window to the specified string.boolean
setUrl(String url)
Sets the URL of the browser to the specified location.void
showDevTools()
Opens a new browser with the DevTools view of the current browser instance.static ChromiumBrowser
standalone(String url)
Create a Standalone browser.static ChromiumBrowser
standalone(String url, int x, int y, int width, int height)
Create a Standalone browser with specific window bounds.static ChromiumBrowser
standalone(String url, org.cef.misc.Rectangle window)
Create a Standalone browser with specific window bounds.static void
startBrowsers()
Start the CEF event loop when creating in Standalone and Windowless browsers.void
stop()
Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.static ChromiumBrowser
swing(Object container, String layout, String url)
Create a Swing browser.static ChromiumBrowser
swing(String url)
Create a Swing browser.static ChromiumBrowser
swt(Object composite, int style)
Create a SWT browser.CompletableFuture<String>
text()
Gets a source text in the browser.static ChromiumBrowser
windowless(String url)
Create a Windowless browser.static ChromiumBrowser
windowless(String url, int x, int y, int width, int height)
Create a Windowless browser with specific window bounds.void
zoom(double zoomLevel)
Change the zoom level to the specified value.
-
-
-
Method Detail
-
getAllBrowsers
static Collection<ChromiumBrowser> getAllBrowsers()
Retrieves a collection of all ChromiumBrowser instances currently active within the application.- Returns:
- Returns all active browsers.
- Since:
- 124.0.0
-
windowless
static ChromiumBrowser windowless(String url)
Create a Windowless browser.- Parameters:
url
- The url that will be loaded in the browser.- Returns:
- Returns a new Windowless browser instance. If an instance of org.eclipse.swt.widgets.Display exists, returns SWT Windowless browser or Standalone Windowless browser otherwise.
- Since:
- 124.0.0
-
windowless
static ChromiumBrowser windowless(String url, int x, int y, int width, int height)
Create a Windowless browser with specific window bounds.- Parameters:
url
- The url that will be loaded in the browser.x
- The x coordinate of the origin of the window.y
- The y coordinate of the origin of the window.width
- The width of the window.height
- The height of the window.- Returns:
- Returns a new Windowless browser instance. If an instance of org.eclipse.swt.widgets.Display exists, returns SWT Windowless browser or Standalone Windowless browser otherwise.
- Since:
- 124.0.0
-
compatibleWithHost
static CompatibleWithHost compatibleWithHost()
Create a CompatibleWithHost constructor. This allows automatic checking of all necessary requirements for the specified toolkit, by default windowless using the specified default java system properties.- Since:
- 116.0.20
-
standalone
static ChromiumBrowser standalone(String url)
Create a Standalone browser.- Parameters:
url
- The url that will be loaded in the browser.- Returns:
- Returns a new Standalone browser instance.
- Throws:
UnsupportedOperationException
- if another type of toolkit has been initialized previously.- Since:
- 124.0.0
-
standalone
static ChromiumBrowser standalone(String url, int x, int y, int width, int height)
Create a Standalone browser with specific window bounds.- Parameters:
url
- The url that will be loaded in the browser.x
- The x coordinate of the origin of the window.y
- The y coordinate of the origin of the window.width
- The width of the window.height
- The height of the window.- Returns:
- Returns a new Standalone browser instance.
- Throws:
UnsupportedOperationException
- if another type of toolkit has been initialized previously.- Since:
- 124.0.0
-
standalone
static ChromiumBrowser standalone(String url, org.cef.misc.Rectangle window)
Create a Standalone browser with specific window bounds.- Parameters:
url
- The url that will be loaded in the browser.window
- Specifies the dimensions that the window will have.- Returns:
- Returns a new Standalone browser instance.
- Throws:
UnsupportedOperationException
- if another type of toolkit has been initialized previously.- Since:
- 124.0.0
-
swing
static ChromiumBrowser swing(Object container, String layout, String url)
Create a Swing browser.- Parameters:
container
- The parent container to contains the browser.layout
- Where the window will be placed.url
- The url that will be loaded in the browser.- Returns:
- Returns a new Swing browser instance.
- Throws:
UnsupportedOperationException
- if another type of toolkit has been initialized previously.- Since:
- 124.0.0
-
swing
static ChromiumBrowser swing(String url)
Create a Swing browser.- Parameters:
url
- The url that will be loaded in the browser.- Returns:
- Returns a new Swing browser instance.
- Throws:
UnsupportedOperationException
- if another type of toolkit has been initialized previously.- Since:
- 124.0.0
-
swt
static ChromiumBrowser swt(Object composite, int style)
Create a SWT browser.- Parameters:
composite
- The parent composite contains the browser.style
- Composite style.- Returns:
- Returns a new SWT browser instance.
- Throws:
UnsupportedOperationException
- if another type of toolkit has been initialized previously.- Since:
- 124.0.0
-
earlyInit
static void earlyInit() throws ClassNotFoundException
Early load and initialize the Equo Chromium engine and libraries. Usually not required.- Throws:
ClassNotFoundException
- Since:
- 124.0.0
-
startBrowsers
static void startBrowsers()
Start the CEF event loop when creating in Standalone and Windowless browsers.- Since:
- 124.0.0
-
clearCookies
static boolean clearCookies(String urlPattern, String namePattern)
/** Delete cookies matching the url and name regex patterns. Negation patterns can be used to exclude cookies from deletion.- Parameters:
urlPattern
- The pattern for the matching URL case. Null matches all, empty matches nothing.namePattern
- The pattern for the matching cookie name case. Null matches all, empty matches nothing.- Returns:
- Returns true if cookies were cleared and false otherwise.
- Since:
- 124.0.0
-
isClosed
boolean isClosed()
Checks if the browser has been closed.- Returns:
- Returns true if the browser was closed and false otherwise.
- Since:
- 124.0.9
-
setUrl
boolean setUrl(String url)
Sets the URL of the browser to the specified location.- Parameters:
url
- The url that will be loaded in the browser.- Returns:
- Returns true if the url was loaded and false otherwise.
- Since:
- 124.0.0
-
setText
boolean setText(String html)
Sets the text content of the browser window to the specified string.- Parameters:
html
- The html that will be loaded in the browser.- Returns:
- Returns true if the html was loaded and false otherwise.
- Since:
- 124.0.0
-
close
boolean close()
- Returns:
- Returns true if the browser will be closed and false otherwise.
- Since:
- 124.0.0
-
executeJavaScript
void executeJavaScript(String script)
Executes JavaScript code within the context of the browser window.- Parameters:
script
- Script to be executed in the browser.- Since:
- 124.0.0
-
executeJavacript
@Deprecated void executeJavacript(String script)
Deprecated. Executes JavaScript code within the context of the browser window. Use executeJavaScript(String) instead.- Parameters:
script
- Script to be executed in the browser.- Since:
- 124.0.0
-
find
void find(String search, boolean forward, boolean matchCase)
Finds text within the browser window based on the specified search criteria.- Parameters:
search
- the text to search for.forward
- indicates whether to search forward or backward in the document.matchCase
- indicates whether the search should be case-sensitive.- Since:
- 124.0.0
-
zoom
void zoom(double zoomLevel)
Change the zoom level to the specified value. Specify 0.0 to reset the zoom level.- Parameters:
zoomLevel
- The zoom level to the specified value.- Since:
- 124.0.0
-
getZoom
double getZoom()
Get the current zoom level.- Returns:
- Returns the current zoom level.
- Since:
- 124.0.0
-
addConsoleListener
void addConsoleListener(ChromiumBrowser.ConsoleListener listener)
Adds a listener to receive console events from the browser.- Parameters:
listener
- The console listener to add.- Since:
- 124.0.0
-
removeConsoleListener
void removeConsoleListener(ChromiumBrowser.ConsoleListener listener)
Removes a previously added console listener from the browser.- Parameters:
listener
- The console listener to remove.- Since:
- 124.0.0
-
getErrors
List<Object> getErrors()
Gets all errors when the rendering process terminates unexpectedly.- Returns:
- Returns the status error list of how the process ended.
- Since:
- 124.0.0
-
captureScreenshot
CompletableFuture<byte[]> captureScreenshot()
Capture screenshot from browser. This method cannot be called from the main thread.- Returns:
- CompletableFuture
which will contain Base64 encoded PNG image data. - Since:
- 124.0.0
-
captureScreenshot
CompletableFuture<byte[]> captureScreenshot(int x, int y, int width, int height, int scale)
Capture screenshots of a specific area. This method cannot be called from the main thread.- Parameters:
x
- The x coordinate of the origin of the window.y
- The y coordinate of the origin of the window.width
- The width of the window.height
- The height of the window.scale
- The scale of the image.- Returns:
- CompletableFuture
which will contain Base64 encoded PNG image data. - Since:
- 124.0.0
-
ignoreCertificateErrors
void ignoreCertificateErrors(boolean enable)
Ignore certificate errors in the browser. If used when the browser is defined, a new request context is created for the browser and will not affect the others. Otherwise, if used with an already initialized browser, it will affect all other browser instances as the change to the global requestContent will be used. Default is false. For browser certificate errors to be ignored it must be called upon creation, otherwise it will have an effect on all other browsers. You can reset certificate errors by calling the method with false.- Parameters:
enable
-- Since:
- 124.0.0
-
getUIComponent
Object getUIComponent()
Gets the Composite or Component UI object, depending on the current toolkit.- Returns:
- Returns the Composite or Component UI object, depending on the current toolkit.
- Since:
- 124.0.0
-
isLoading
boolean isLoading()
Checks whether the browser is currently loading a page.- Returns:
- Returns true if the browser is loading a page or false otherwise.
- Since:
- 124.0.0
-
goBack
void goBack()
Loads the previous location in the back-forward list.- Since:
- 124.0.0
-
goForward
void goForward()
Loads the next location in the back-forward list.- Since:
- 124.0.0
-
canGoBack
boolean canGoBack()
Checks whether there is a previous page to navigate back to in the browsing history.- Returns:
- Returns true if the previous location can be loaded and false otherwise.
- Since:
- 124.0.0
-
canGoForward
boolean canGoForward()
Checks whether there is a subsequent page to navigate forward to in the browsing history.- Returns:
- Returns true if the next location can be loaded and false otherwise.
- Since:
- 124.0.0
-
reload
void reload()
Reloads the currently loaded web page.- Since:
- 124.0.0
-
stop
void stop()
Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.- Since:
- 124.0.0
-
text
CompletableFuture<String> text()
Gets a source text in the browser.- Returns:
- Returns a source text in the browser.
- Since:
- 124.0.0
-
getUrl
String getUrl()
Gets the current url.- Returns:
- Returns the current url.
- Since:
- 124.0.0
-
isCreated
CompletableFuture<Boolean> isCreated()
Checks whether the browser has been created.- Returns:
- a CompletableFuture
that will be completed with a boolean value indicating whether the browser has been created - Since:
- 124.0.0
-
showDevTools
void showDevTools()
Opens a new browser with the DevTools view of the current browser instance.- Since:
- 124.0.0
-
printToPdf
CompletableFuture<Boolean> printToPdf(String path, PdfPrintSettings settings)
Print the current browser contents as a PDF.- Parameters:
path
- The path of the file to write to (will be overwritten if it already exists). Cannot be null.settings
- The PDF print settings to use. If null then defaults will be used.- Since:
- 124.0.0
-
printToPdf
CompletableFuture<Boolean> printToPdf(String path)
Print the current browser contents as a PDF.- Parameters:
path
- The path of the file to write to (will be overwritten if it already exists). Cannot be null.- Since:
- 124.0.0
-
getLocalStorage
com.equo.chromium.Storage getLocalStorage()
Returns an instance of LocalStorage.- Since:
- 124.0.0
-
getSessionStorage
com.equo.chromium.Storage getSessionStorage()
Returns an instance of SessionStorage.- Since:
- 124.0.0
-
-
Copyright © 2024. All rights reserved.