Package org.htmlunit

Class WebClient

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.AutoCloseable

    public class WebClient
    extends java.lang.Object
    implements java.io.Serializable, java.lang.AutoCloseable
    The main starting point in HtmlUnit: this class simulates a web browser.

    A standard usage of HtmlUnit will start with using the getPage(String) method (or getPage(URL)) to load a first Page and will continue with further processing on this page depending on its type.

    Example:

    final WebClient webClient = new WebClient();
    final HtmlPage startPage = webClient.getPage("http://htmlunit.sf.net");
    assertEquals("HtmlUnit - Welcome to HtmlUnit", startPage.getTitleText());

    Note: a WebClient instance is not thread safe. It is intended to be used from a single thread.

    See Also:
    Serialized Form
    • Field Detail

      • TARGET_BLANK

        public static final java.lang.String TARGET_BLANK
        target "_blank".
        See Also:
        Constant Field Values
      • TARGET_SELF

        public static final java.lang.String TARGET_SELF
        target "_self".
        See Also:
        Constant Field Values
    • Constructor Detail

      • WebClient

        public WebClient​(BrowserVersion browserVersion)
        Creates a web client instance using the specified BrowserVersion.
        Parameters:
        browserVersion - the browser version to simulate
      • WebClient

        public WebClient​(BrowserVersion browserVersion,
                         java.lang.String proxyHost,
                         int proxyPort)
        Creates an instance that will use the specified BrowserVersion and proxy server.
        Parameters:
        browserVersion - the browser version to simulate
        proxyHost - the server that will act as proxy or null for no proxy
        proxyPort - the port to use on the proxy server
      • WebClient

        public WebClient​(BrowserVersion browserVersion,
                         java.lang.String proxyHost,
                         int proxyPort,
                         java.lang.String proxyScheme)
        Creates an instance that will use the specified BrowserVersion and proxy server.
        Parameters:
        browserVersion - the browser version to simulate
        proxyHost - the server that will act as proxy or null for no proxy
        proxyPort - the port to use on the proxy server
        proxyScheme - the scheme http/https
      • WebClient

        public WebClient​(BrowserVersion browserVersion,
                         boolean javaScriptEngineEnabled,
                         java.lang.String proxyHost,
                         int proxyPort)
        Creates an instance that will use the specified BrowserVersion and proxy server.
        Parameters:
        browserVersion - the browser version to simulate
        javaScriptEngineEnabled - set to false if the simulated browser should not support javaScript
        proxyHost - the server that will act as proxy or null for no proxy
        proxyPort - the port to use on the proxy server
      • WebClient

        public WebClient​(BrowserVersion browserVersion,
                         boolean javaScriptEngineEnabled,
                         java.lang.String proxyHost,
                         int proxyPort,
                         java.lang.String proxyScheme)
        Creates an instance that will use the specified BrowserVersion and proxy server.
        Parameters:
        browserVersion - the browser version to simulate
        javaScriptEngineEnabled - set to false if the simulated browser should not support javaScript
        proxyHost - the server that will act as proxy or null for no proxy
        proxyPort - the port to use on the proxy server
        proxyScheme - the scheme http/https
    • Method Detail

      • getWebConnection

        public WebConnection getWebConnection()
        Returns the object that will resolve all URL requests.
        Returns:
        the connection that will be used
      • setWebConnection

        public void setWebConnection​(WebConnection webConnection)
        Sets the object that will resolve all URL requests.
        Parameters:
        webConnection - the new web connection
      • loadWebResponseInto

        public Page loadWebResponseInto​(WebResponse webResponse,
                                        WebWindow webWindow)
                                 throws java.io.IOException,
                                        FailingHttpStatusCodeException

        Creates a page based on the specified response and inserts it into the specified window. All page initialization and event notification is handled here.

        Note that if the page created is an attachment page, and an AttachmentHandler has been registered with this client, the page is not loaded into the specified window; in this case, the page is loaded into a new window, and attachment handling is delegated to the registered AttachmentHandler.

        Parameters:
        webResponse - the response that will be used to create the new page
        webWindow - the window that the new page will be placed within
        Returns:
        the newly created page
        Throws:
        java.io.IOException - if an IO error occurs
        FailingHttpStatusCodeException - if the server returns a failing status code AND the property WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean) is set to true
        See Also:
        setAttachmentHandler(AttachmentHandler)
      • loadWebResponseInto

        public Page loadWebResponseInto​(WebResponse webResponse,
                                        WebWindow webWindow,
                                        boolean forceAttachment)
                                 throws java.io.IOException,
                                        FailingHttpStatusCodeException
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

        Creates a page based on the specified response and inserts it into the specified window. All page initialization and event notification is handled here.

        Note that if the page created is an attachment page, and an AttachmentHandler has been registered with this client, the page is not loaded into the specified window; in this case, the page is loaded into a new window, and attachment handling is delegated to the registered AttachmentHandler.

        Parameters:
        webResponse - the response that will be used to create the new page
        webWindow - the window that the new page will be placed within
        forceAttachment - handle this as attachment (is set to true if the call was triggered from anchor with download property set).
        Returns:
        the newly created page
        Throws:
        java.io.IOException - if an IO error occurs
        FailingHttpStatusCodeException - if the server returns a failing status code AND the property WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean) is set to true
        See Also:
        setAttachmentHandler(AttachmentHandler)
      • printContentIfNecessary

        public void printContentIfNecessary​(WebResponse webResponse)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

        Logs the response's content if its status code indicates a request failure and WebClientOptions.isPrintContentOnFailingStatusCode() returns true.

        Parameters:
        webResponse - the response whose content may be logged
      • addRequestHeader

        public void addRequestHeader​(java.lang.String name,
                                     java.lang.String value)
        Adds a header which will be sent with EVERY request from this client. This list is empty per default; use this to add specific headers for your case.
        Parameters:
        name - the name of the header to add
        value - the value of the header to add
        See Also:
        removeRequestHeader(String)
      • removeRequestHeader

        public void removeRequestHeader​(java.lang.String name)
        Removes a header from being sent with EVERY request from this client. This list is empty per default; use this method to remove specific headers your have added using {addRequestHeader(String, String) before.
        You can't use this to avoid sending standard headers like "Accept-Language" or "Sec-Fetch-Dest".
        Parameters:
        name - the name of the header to remove
        See Also:
        addRequestHeader(java.lang.String, java.lang.String)
      • setCredentialsProvider

        public void setCredentialsProvider​(org.apache.http.client.CredentialsProvider credentialsProvider)
        Sets the credentials provider that will provide authentication information when trying to access protected information on a web server. This information is required when the server is using Basic HTTP authentication, NTLM authentication, or Digest authentication.
        Parameters:
        credentialsProvider - the new credentials provider to use to authenticate
      • getCredentialsProvider

        public org.apache.http.client.CredentialsProvider getCredentialsProvider()
        Returns the credentials provider for this client instance. By default, this method returns an instance of DefaultCredentialsProvider.
        Returns:
        the credentials provider for this client instance
      • getJavaScriptEngine

        public org.htmlunit.javascript.AbstractJavaScriptEngine<?> getJavaScriptEngine()
        This method is intended for testing only - use at your own risk.
        Returns:
        the current JavaScript engine (never null)
      • setJavaScriptEngine

        public void setJavaScriptEngine​(org.htmlunit.javascript.AbstractJavaScriptEngine<?> engine)
        This method is intended for testing only - use at your own risk.
        Parameters:
        engine - the new script engine to use
      • getCookieManager

        public CookieManager getCookieManager()
        Returns the cookie manager used by this web client.
        Returns:
        the cookie manager used by this web client
      • setCookieManager

        public void setCookieManager​(CookieManager cookieManager)
        Sets the cookie manager used by this web client.
        Parameters:
        cookieManager - the cookie manager used by this web client
      • setAlertHandler

        public void setAlertHandler​(AlertHandler alertHandler)
        Sets the alert handler for this webclient.
        Parameters:
        alertHandler - the new alerthandler or null if none is specified
      • getAlertHandler

        public AlertHandler getAlertHandler()
        Returns the alert handler for this webclient.
        Returns:
        the alert handler or null if one hasn't been set
      • setConfirmHandler

        public void setConfirmHandler​(ConfirmHandler handler)
        Sets the handler that will be executed when the JavaScript method Window.confirm() is called.
        Parameters:
        handler - the new handler or null if no handler is to be used
      • getConfirmHandler

        public ConfirmHandler getConfirmHandler()
        Returns the confirm handler.
        Returns:
        the confirm handler or null if one hasn't been set
      • setPromptHandler

        public void setPromptHandler​(PromptHandler handler)
        Sets the handler that will be executed when the JavaScript method Window.prompt() is called.
        Parameters:
        handler - the new handler or null if no handler is to be used
      • getPromptHandler

        public PromptHandler getPromptHandler()
        Returns the prompt handler.
        Returns:
        the prompt handler or null if one hasn't been set
      • setStatusHandler

        public void setStatusHandler​(StatusHandler statusHandler)
        Sets the status handler for this webclient.
        Parameters:
        statusHandler - the new status handler or null if none is specified
      • getStatusHandler

        public StatusHandler getStatusHandler()
        Returns the status handler for this WebClient.
        Returns:
        the status handler or null if one hasn't been set
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
        Returns the executor for this WebClient.
        Returns:
        the executor
      • setExecutor

        public void setExecutor​(java.util.concurrent.ExecutorService executor)
        Changes the ExecutorService for this WebClient. You have to call this before the first use of the executor, otherwise an IllegalStateExceptions is thrown.
        Parameters:
        executor - the new Executor.
      • setJavaScriptErrorListener

        public void setJavaScriptErrorListener​(org.htmlunit.javascript.JavaScriptErrorListener javaScriptErrorListener)
        Sets the javascript error listener for this WebClient. When setting to null, the DefaultJavaScriptErrorListener is used.
        Parameters:
        javaScriptErrorListener - the new JavaScriptErrorListener or null if none is specified
      • getJavaScriptErrorListener

        public org.htmlunit.javascript.JavaScriptErrorListener getJavaScriptErrorListener()
        Returns the javascript error listener for this WebClient.
        Returns:
        the javascript error listener or null if one hasn't been set
      • getBrowserVersion

        public BrowserVersion getBrowserVersion()
        Returns the current browser version.
        Returns:
        the current browser version
      • getCurrentWindow

        public WebWindow getCurrentWindow()
        Returns the "current" window for this client. This window (or its top window) will be used when getPage(...) is called without specifying a window.
        Returns:
        the "current" window for this client
      • setCurrentWindow

        public void setCurrentWindow​(WebWindow window)
        Sets the "current" window for this client. This is the window that will be used when getPage(...) is called without specifying a window.
        Parameters:
        window - the new "current" window for this client
      • addWebWindowListener

        public void addWebWindowListener​(WebWindowListener listener)
        Adds a listener for WebWindowEvents. All events from all windows associated with this client will be sent to the specified listener.
        Parameters:
        listener - a listener
      • removeWebWindowListener

        public void removeWebWindowListener​(WebWindowListener listener)
        Removes a listener for WebWindowEvents.
        Parameters:
        listener - a listener
      • openWindow

        public WebWindow openWindow​(java.net.URL url,
                                    java.lang.String windowName)
        Open a new window with the specified name. If the URL is non-null then attempt to load a page from that location and put it in the new window.
        Parameters:
        url - the URL to load content from or null if no content is to be loaded
        windowName - the name of the new window
        Returns:
        the new window
      • openWindow

        public WebWindow openWindow​(java.net.URL url,
                                    java.lang.String windowName,
                                    WebWindow opener)
        Open a new window with the specified name. If the URL is non-null then attempt to load a page from that location and put it in the new window.
        Parameters:
        url - the URL to load content from or null if no content is to be loaded
        windowName - the name of the new window
        opener - the web window that is calling openWindow
        Returns:
        the new window
      • openTargetWindow

        public WebWindow openTargetWindow​(WebWindow opener,
                                          java.lang.String windowName,
                                          java.lang.String defaultName)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Open the window with the specified name. The name may be a special target name of _self, _parent, _top, or _blank. An empty or null name is set to the default. The special target names are relative to the opener window.
        Parameters:
        opener - the web window that is calling openWindow
        windowName - the name of the new window
        defaultName - the default target if no name is given
        Returns:
        the new window
      • openDialogWindow

        public DialogWindow openDialogWindow​(java.net.URL url,
                                             WebWindow opener,
                                             java.lang.Object dialogArguments)
                                      throws java.io.IOException

        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

        Opens a new dialog window.
        Parameters:
        url - the URL of the document to load and display
        opener - the web window that is opening the dialog
        dialogArguments - the object to make available inside the dialog via window.dialogArguments
        Returns:
        the new dialog window
        Throws:
        java.io.IOException - if there is an IO error
      • setPageCreator

        public void setPageCreator​(PageCreator pageCreator)
        Sets the object that will be used to create pages. Set this if you want to customize the type of page that is returned for a given content type.
        Parameters:
        pageCreator - the new page creator
      • getPageCreator

        public PageCreator getPageCreator()
        Returns the current page creator.
        Returns:
        the page creator
      • initialize

        public void initialize​(WebWindow webWindow,
                               Page page)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Initializes a new web window for JavaScript.
        Parameters:
        webWindow - the new WebWindow
        page - the page that will become the enclosing page
      • initializeEmptyWindow

        public void initializeEmptyWindow​(WebWindow webWindow,
                                          Page page)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Initializes a new empty window for JavaScript.
        Parameters:
        webWindow - the new WebWindow
        page - the page that will become the enclosing page
      • registerWebWindow

        public void registerWebWindow​(WebWindow webWindow)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Adds a new window to the list of available windows.
        Parameters:
        webWindow - the new WebWindow
      • deregisterWebWindow

        public void deregisterWebWindow​(WebWindow webWindow)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Removes a window from the list of available windows.
        Parameters:
        webWindow - the window to remove
      • expandUrl

        public static java.net.URL expandUrl​(java.net.URL baseUrl,
                                             java.lang.String relativeUrl)
                                      throws java.net.MalformedURLException
        Expands a relative URL relative to the specified base. In most situations this is the same as new URL(baseUrl, relativeUrl) but there are some cases that URL doesn't handle correctly. See RFC1808 regarding Relative Uniform Resource Locators for more information.
        Parameters:
        baseUrl - the base URL
        relativeUrl - the relative URL
        Returns:
        the expansion of the specified base and relative URLs
        Throws:
        java.net.MalformedURLException - if an error occurred when creating a URL object
      • guessContentType

        public java.lang.String guessContentType​(java.io.File file)
        Tries to guess the content type of the file.
        This utility could be located in a helper class but we can compare this functionality for instance with the "Helper Applications" settings of Mozilla and therefore see it as a property of the "browser".
        Parameters:
        file - the file
        Returns:
        "application/octet-stream" if nothing could be guessed
      • loadWebResponse

        public WebResponse loadWebResponse​(WebRequest webRequest)
                                    throws java.io.IOException
        Loads a WebResponse from the server.
        Parameters:
        webRequest - the request
        Returns:
        the WebResponse
        Throws:
        java.io.IOException - if an IO problem occurs
      • getWebWindows

        public java.util.List<WebWindow> getWebWindows()
        Returns an immutable list of open web windows (whether they are top level windows or not). This is a snapshot; future changes are not reflected by this list.

        The list is ordered by age, the oldest one first.

        Returns:
        an immutable list of open web windows (whether they are top level windows or not)
        See Also:
        getWebWindowByName(String), getTopLevelWindows()
      • containsWebWindow

        public boolean containsWebWindow​(WebWindow webWindow)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns true if the list of WebWindows contains the provided one. This method is there to improve the performance of some internal checks because calling getWebWindows().contains(.) creates some objects without any need.
        Parameters:
        webWindow - the window to check
        Returns:
        true or false
      • getTopLevelWindows

        public java.util.List<TopLevelWindow> getTopLevelWindows()
        Returns an immutable list of open top level windows. This is a snapshot; future changes are not reflected by this list.

        The list is ordered by age, the oldest one first.

        Returns:
        an immutable list of open top level windows
        See Also:
        getWebWindowByName(String), getWebWindows()
      • setRefreshHandler

        public void setRefreshHandler​(RefreshHandler handler)
        Sets the handler to be used whenever a refresh is triggered. Refer to the documentation for RefreshHandler for more details.
        Parameters:
        handler - the new handler
      • getRefreshHandler

        public RefreshHandler getRefreshHandler()
        Returns the current refresh handler. The default refresh handler is a NiceRefreshHandler(2).
        Returns:
        the current RefreshHandler
      • setScriptPreProcessor

        public void setScriptPreProcessor​(ScriptPreProcessor scriptPreProcessor)
        Sets the script pre processor for this WebClient.
        Parameters:
        scriptPreProcessor - the new preprocessor or null if none is specified
      • getScriptPreProcessor

        public ScriptPreProcessor getScriptPreProcessor()
        Returns the script pre processor for this WebClient.
        Returns:
        the pre processor or null of one hasn't been set
      • setActiveXObjectMap

        public void setActiveXObjectMap​(java.util.Map<java.lang.String,​java.lang.String> activeXObjectMap)
        Sets the active X object map for this WebClient. The Map is used to map the string passed into the ActiveXObject constructor to a java class name. Therefore you can emulate ActiveXObjects in a web page's JavaScript by mapping the object name to a java class to emulate the active X object.
        Parameters:
        activeXObjectMap - the new preprocessor or null if none is specified
      • getActiveXObjectMap

        public java.util.Map<java.lang.String,​java.lang.String> getActiveXObjectMap()
        Returns the active X object map for this WebClient.
        Returns:
        the active X object map
      • getMSXMLActiveXObjectFactory

        public org.htmlunit.activex.javascript.msxml.MSXMLActiveXObjectFactory getMSXMLActiveXObjectFactory()
        Returns the MSXML ActiveX object factory (if supported).
        Returns:
        the msxmlActiveXObjectFactory
      • setHTMLParserListener

        public void setHTMLParserListener​(org.htmlunit.html.parser.HTMLParserListener listener)
        Sets the listener for messages generated by the HTML parser.
        Parameters:
        listener - the new listener, null if messages should be totally ignored
      • getHTMLParserListener

        public org.htmlunit.html.parser.HTMLParserListener getHTMLParserListener()
        Gets the configured listener for messages generated by the HTML parser.
        Returns:
        null if no listener is defined (default value)
      • getCssErrorHandler

        public org.htmlunit.cssparser.parser.CSSErrorHandler getCssErrorHandler()
        Returns the CSS error handler used by this web client when CSS problems are encountered.
        Returns:
        the CSS error handler used by this web client when CSS problems are encountered
        See Also:
        DefaultCssErrorHandler, SilentCssErrorHandler
      • setCssErrorHandler

        public void setCssErrorHandler​(org.htmlunit.cssparser.parser.CSSErrorHandler cssErrorHandler)
        Sets the CSS error handler used by this web client when CSS problems are encountered.
        Parameters:
        cssErrorHandler - the CSS error handler used by this web client when CSS problems are encountered
        See Also:
        DefaultCssErrorHandler, SilentCssErrorHandler
      • setJavaScriptTimeout

        public void setJavaScriptTimeout​(long timeout)
        Sets the number of milliseconds that a script is allowed to execute before being terminated. A value of 0 or less means no timeout.
        Parameters:
        timeout - the timeout value, in milliseconds
      • getJavaScriptTimeout

        public long getJavaScriptTimeout()
        Returns the number of milliseconds that a script is allowed to execute before being terminated. A value of 0 or less means no timeout.
        Returns:
        the timeout value, in milliseconds
      • getIncorrectnessListener

        public IncorrectnessListener getIncorrectnessListener()
        Gets the current listener for encountered incorrectness (except HTML parsing messages that are handled by the HTML parser listener). Default value is an instance of IncorrectnessListenerImpl.
        Returns:
        the current listener (not null)
      • setIncorrectnessListener

        public void setIncorrectnessListener​(IncorrectnessListener listener)
        Returns the current HTML incorrectness listener.
        Parameters:
        listener - the new value (not null)
      • getWebConsole

        public WebConsole getWebConsole()
        Returns the WebConsole.
        Returns:
        the web console
      • getAjaxController

        public AjaxController getAjaxController()
        Gets the current AJAX controller.
        Returns:
        the controller
      • setAjaxController

        public void setAjaxController​(AjaxController newValue)
        Sets the current AJAX controller.
        Parameters:
        newValue - the controller
      • setAttachmentHandler

        public void setAttachmentHandler​(AttachmentHandler handler)
        Sets the attachment handler.
        Parameters:
        handler - the new attachment handler
      • getAttachmentHandler

        public AttachmentHandler getAttachmentHandler()
        Returns the current attachment handler.
        Returns:
        the current attachment handler
      • setWebStartHandler

        public void setWebStartHandler​(org.htmlunit.webstart.WebStartHandler handler)
        Sets the WebStart handler.
        Parameters:
        handler - the new WebStart handler
      • getWebStartHandler

        public org.htmlunit.webstart.WebStartHandler getWebStartHandler()
        Returns the current WebStart handler.
        Returns:
        the current WebStart handler
      • getClipboardHandler

        public ClipboardHandler getClipboardHandler()
        Returns the current clipboard handler.
        Returns:
        the current clipboard handler
      • setClipboardHandler

        public void setClipboardHandler​(ClipboardHandler handler)
        Sets the clipboard handler.
        Parameters:
        handler - the new clipboard handler
      • setPrintHandler

        public void setPrintHandler​(PrintHandler handler)
        Sets the PrintHandler to be used if Windoe.print() is called (Printing Spec).
        Parameters:
        handler - the new PrintHandler or null if you like to ignore print requests (default is null)
      • setAppletConfirmHandler

        public void setAppletConfirmHandler​(AppletConfirmHandler handler)
        Sets the applet confirm handler.
        Parameters:
        handler - the new applet confirm handler handler
      • getAppletConfirmHandler

        public AppletConfirmHandler getAppletConfirmHandler()
        Returns the current applet confirm handler.
        Returns:
        the current applet confirm handler
      • getFrameContentHandler

        public FrameContentHandler getFrameContentHandler()
        Returns the current FrameContent handler.
        Returns:
        the current FrameContent handler
      • setFrameContentHandler

        public void setFrameContentHandler​(FrameContentHandler handler)
        Sets the FrameContent handler.
        Parameters:
        handler - the new FrameContent handler
      • setOnbeforeunloadHandler

        public void setOnbeforeunloadHandler​(OnbeforeunloadHandler onbeforeunloadHandler)
        Sets the onbeforeunload handler for this WebClient.
        Parameters:
        onbeforeunloadHandler - the new onbeforeunloadHandler or null if none is specified
      • getOnbeforeunloadHandler

        public OnbeforeunloadHandler getOnbeforeunloadHandler()
        Returns the onbeforeunload handler for this WebClient.
        Returns:
        the onbeforeunload handler or null if one hasn't been set
      • getCache

        public Cache getCache()
        Gets the cache currently being used.
        Returns:
        the cache (may not be null)
      • setCache

        public void setCache​(Cache cache)
        Sets the cache to use.
        Parameters:
        cache - the new cache (must not be null)
      • close

        public void close()
        Closes all opened windows, stopping all background JavaScript processing. The WebClient is not really usable after this - you have to create a new one or use WebClient.reset() instead.

        Specified by:
        close in interface java.lang.AutoCloseable
      • reset

        public void reset()

        Experimental API: May be changed in next release and may not yet work perfectly!

        This shuts down the whole client and restarts with a new empty window. Cookies and other states are preserved.

      • waitForBackgroundJavaScript

        public int waitForBackgroundJavaScript​(long timeoutMillis)

        Experimental API: May be changed in next release and may not yet work perfectly!

        This method blocks until all background JavaScript tasks have finished executing. Background JavaScript tasks are JavaScript tasks scheduled for execution via window.setTimeout, window.setInterval or asynchronous XMLHttpRequest.

        If a job is scheduled to begin executing after (now + timeoutMillis), this method will wait for timeoutMillis milliseconds and then return a value greater than 0. This method will never block longer than timeoutMillis milliseconds.

        Use this method instead of waitForBackgroundJavaScriptStartingBefore(long) if you don't know when your background JavaScript is supposed to start executing, but you're fairly sure that you know how long it should take to finish executing.

        Parameters:
        timeoutMillis - the maximum amount of time to wait (in milliseconds)
        Returns:
        the number of background JavaScript jobs still executing or waiting to be executed when this method returns; will be 0 if there are no jobs left to execute
      • waitForBackgroundJavaScriptStartingBefore

        public int waitForBackgroundJavaScriptStartingBefore​(long delayMillis)

        Experimental API: May be changed in next release and may not yet work perfectly!

        This method blocks until all background JavaScript tasks scheduled to start executing before (now + delayMillis) have finished executing. Background JavaScript tasks are JavaScript tasks scheduled for execution via window.setTimeout, window.setInterval or asynchronous XMLHttpRequest.

        If there is no background JavaScript task currently executing, and there is no background JavaScript task scheduled to start executing within the specified time, this method returns immediately -- even if there are tasks scheduled to be executed after (now + delayMillis).

        Note that the total time spent executing a background JavaScript task is never known ahead of time, so this method makes no guarantees as to how long it will block.

        Use this method instead of waitForBackgroundJavaScript(long) if you know roughly when your background JavaScript is supposed to start executing, but you're not necessarily sure how long it will take to execute.

        Parameters:
        delayMillis - the delay which determines the background tasks to wait for (in milliseconds)
        Returns:
        the number of background JavaScript jobs still executing or waiting to be executed when this method returns; will be 0 if there are no jobs left to execute
      • download

        public void download​(WebWindow requestingWindow,
                             java.lang.String target,
                             WebRequest request,
                             boolean checkHash,
                             boolean forceLoad,
                             boolean forceAttachment,
                             java.lang.String description)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Perform the downloads and stores it for loading later into a window. In the future downloads should be performed in parallel in separated threads. TODO: refactor it before next release.
        Parameters:
        requestingWindow - the window from which the request comes
        target - the name of the target window
        request - the request to perform
        checkHash - if true check for hashChenage
        forceLoad - if true always load the request even if there is already the same in the queue
        forceAttachment - if true the AttachmentHandler isAttachment() method is not called, the response has to be handled as attachment in any case
        description - information about the origin of the request. Useful for debugging.
      • loadDownloadedResponses

        public void loadDownloadedResponses()
                                     throws FailingHttpStatusCodeException,
                                            java.io.IOException
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Loads downloaded responses into the corresponding windows. TODO: refactor it before next release.
        Throws:
        java.io.IOException - in case of exception
        FailingHttpStatusCodeException - in case of exception
      • getOptions

        public WebClientOptions getOptions()
        Returns the options object of this WebClient.
        Returns:
        the options object
      • getInternals

        public WebClientInternals getInternals()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns the internals object of this WebClient.
        Returns:
        the internals object
      • getStorageHolder

        public StorageHolder getStorageHolder()
        Gets the holder for the different storages.

        Experimental API: May be changed in next release!

        Returns:
        the holder
      • getCookies

        public java.util.Set<Cookie> getCookies​(java.net.URL url)
        Returns the currently configured cookies applicable to the specified URL, in an unmodifiable set. If disabled, this returns an empty set.
        Parameters:
        url - the URL on which to filter the returned cookies
        Returns:
        the currently configured cookies applicable to the specified URL, in an unmodifiable set
      • addCookie

        public void addCookie​(java.lang.String cookieString,
                              java.net.URL pageUrl,
                              java.lang.Object origin)
        Parses the given cookie and adds this to our cookie store.
        Parameters:
        cookieString - the string to parse
        pageUrl - the url of the page that likes to set the cookie
        origin - the requester
      • isJavaScriptEngineEnabled

        public boolean isJavaScriptEngineEnabled()
        Returns true if the javaScript engine is enabled. To disable the javascript engine you have to use the WebClient(BrowserVersion, boolean, String, int) constructor.
        Returns:
        true if the javaScript engine is enabled.
      • loadHtmlCodeIntoCurrentWindow

        public HtmlPage loadHtmlCodeIntoCurrentWindow​(java.lang.String htmlCode)
                                               throws java.io.IOException
        Parses the given XHtml code string and loads the resulting XHtmlPage into the current window.
        Parameters:
        htmlCode - the html code as string
        Returns:
        the HtmlPage
        Throws:
        java.io.IOException - in case of error
      • loadXHtmlCodeIntoCurrentWindow

        public XHtmlPage loadXHtmlCodeIntoCurrentWindow​(java.lang.String xhtmlCode)
                                                 throws java.io.IOException
        Parses the given XHtml code string and loads the resulting XHtmlPage into the current window.
        Parameters:
        xhtmlCode - the xhtml code as string
        Returns:
        the XHtmlPage
        Throws:
        java.io.IOException - in case of error
      • getCSS3Parser

        public WebClient.PooledCSS3Parser getCSS3Parser()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Returns:
        a CSS3Parser that will return to an internal pool for reuse if closed using the try-with-resource concept
      • isLoadStaticContent

        @Deprecated
        public boolean isLoadStaticContent()
        Deprecated.
        Returns whether or not download of static content is enabled.

        XLT-specific internal API. May be removed in next release without further notice.

        This is a dummy implementation that just returns true.

        Returns:
        true