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.
    • 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:
        95.0.1
      • 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:
        95.0.1
      • 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:
        95.0.10
      • 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:
        95.0.1
      • 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:
        95.0.10
      • 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:
        95.0.1
      • 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:
        95.0.7
      • 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:
        95.0.7
      • 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:
        95.0.9
      • startBrowsers

        static void startBrowsers()
        Start the CEF event loop when creating in Standalone and Windowless browsers.
        Since:
        95.0.1
      • 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.
        Since:
        95.0.1
      • 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:
        95.0.1
      • 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:
        95.0.7
      • evaluate

        Object evaluate​(String script)
        Deprecated.
        Evaluates the specified script within the context of the browser window. Use Comm instead.
        Parameters:
        script - The script to be evaluated.
        Returns:
        Returns the result of evaluating the script.
        Since:
        95.0.1
        See Also:
        Comm dcoumentation
      • close

        boolean close()
        Closes the browser.
        Returns:
        Returns true if the browser will be closed and false otherwise.
        Since:
        95.0.1
      • executeJavacript

        void executeJavacript​(String script)
        Executes JavaScript code within the context of the browser window.
        Parameters:
        script - Script to be executed in the browser.
        Since:
        95.0.1
      • 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:
        95.0.1
      • 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:
        95.0.1
      • getZoom

        double getZoom()
        Get the current zoom level.
        Returns:
        Returns the current zoom level.
        Since:
        95.0.9
      • addConsoleListener

        void addConsoleListener​(ChromiumBrowser.ConsoleListener listener)
        Adds a listener to receive console events from the browser.
        Parameters:
        listener - The console listener to add.
        Since:
        95.0.1
      • removeConsoleListener

        void removeConsoleListener​(ChromiumBrowser.ConsoleListener listener)
        Removes a previously added console listener from the browser.
        Parameters:
        listener - The console listener to remove.
        Since:
        95.0.1
      • 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:
        95.0.1
      • captureScreenshot

        CompletableFuture<byte[]> captureScreenshot()
        Capture screenshot from browser.
        Returns:
        CompletableFuture which will contain Base64 encoded PNG image data.
        Since:
        95.0.1
      • captureScreenshot

        CompletableFuture<byte[]> captureScreenshot​(int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    int scale)
        Capture screenshots of a specific area.
        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:
        95.0.1
      • 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:
        95.0.1
      • 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:
        95.0.9
      • 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:
        95.0.9
      • goBack

        void goBack()
        Loads the previous location in the back-forward list.
        Since:
        95.0.9
      • goForward

        void goForward()
        Loads the next location in the back-forward list.
        Since:
        95.0.9
      • 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:
        95.0.9
      • 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:
        95.0.9
      • reload

        void reload()
        Reloads the currently loaded web page.
        Since:
        95.0.9
      • stop

        void stop()
        Cancels any pending navigation or download operation and stops any dynamic page elements, such as background sounds and animations.
        Since:
        95.0.9
      • text

        CompletableFuture<String> text()
        Gets a source text in the browser.
        Returns:
        Returns a source text in the browser.
        Since:
        95.0.9
      • getUrl

        String getUrl()
        Gets the current url.
        Returns:
        Returns the current url.
        Since:
        95.0.9
      • 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:
        95.0.9
      • showDevTools

        void showDevTools()
        Opens a new browser with the DevTools view of the current browser instance.
        Since:
        95.0.11
      • 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:
        95.0.16
      • 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:
        95.0.16