Class WebJS

  • All Implemented Interfaces:

    
    public final class WebJS
    
                        

    Convenience class to eval js on web pages

    • Constructor Detail

      • WebJS

        WebJS(Context context, WebView wb)
        Parameters:
        context - Context to create webview
    • Method Detail

      • evalOnFinish

         final Unit evalOnFinish(String link, String userAgent, Map<String, String> headers, Long timeout, String js, Function1<String, Unit> callback)

        Eval de js code on the link after being loaded in a Webview

        Parameters:
        link - Link to be loaded in the webview
        userAgent - Optional user agent to be used while loading the link
        headers - Optional additional headers
        timeout - Time to wait after onPageFinished is called before getting the cookies
        callback - Callback of eval code result
      • cookiesOnFinish

         final Unit cookiesOnFinish(String link, String userAgent, Map<String, String> headers, Long timeout, Function1<String, Unit> cookies)

        Get the cookies of the link after being loaded in a Webview

        Parameters:
        link - Link to be loaded in the webview
        userAgent - Optional user agent to be used while loading the link
        headers - Optional additional headers
        timeout - Time to wait after onPageFinished is called before getting the cookies
        cookies - Callback of the cookies from the link
      • listenResources

         final Unit listenResources(String link, String userAgent, Map<String, String> headers, Long timeout, String executeOnFinish, Function2<String, Map<String, String>, Boolean> filter, Function2<String, Map<String, String>, Unit> callback)

        Listen for network resources while loading a page and return the first one that matches the filter.

        This function loads the specified link in a WebView and intercepts network requests. It uses the provided filter to identify a target resource. Once the page loading is finished (or the timeout is reached), the callback is invoked with the URL and headers of the first matched resource.

        Parameters:
        link - The URL to load in the WebView
        userAgent - The user agent string to use for the request
        headers - A map of additional headers to include in the main request.
        timeout - The maximum time in milliseconds to wait after the page has finished loading before invoking the callback.
        executeOnFinish - Optional JavaScript code to execute after the page has finished loading (javascript:<code>)
        filter - A lambda function that takes a resource URL (as a String?) and returns true if it's the desired resource, false otherwise
        callback - A lambda function to be invoked with the URL and headers of the matched resource.
      • evalJs

         final Unit evalJs(String code, Function1<String, Unit> result)

        Eval js on a webview

        Parameters:
        code - Code to eval
        result - Callback of the eval code result