Package knf.hydra.core.tools.web
Class WebJS
-
- All Implemented Interfaces:
public final class WebJSConvenience class to eval js on web pages
-
-
Constructor Summary
Constructors Constructor Description WebJS(Context context, WebView wb)
-
Method Summary
Modifier and Type Method Description final UnitevalOnFinish(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 final UnitcookiesOnFinish(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 final UnitlistenResources(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. final UnitevalJs(String code, Function1<String, Unit> result)Eval js on a webview -
-
Method Detail
-
evalOnFinish
final Unit evalOnFinish(String link, String userAgent, Map<String, String> headers, Long timeout, String js, Function1<String, Unit> callback)
- Parameters:
link- Link to be loaded in the webviewuserAgent- Optional user agent to be used while loading the linkheaders- Optional additional headerstimeout- Time to wait after onPageFinished is called before getting the cookiescallback- 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 webviewuserAgent- Optional user agent to be used while loading the linkheaders- Optional additional headerstimeout- Time to wait after onPageFinished is called before getting the cookiescookies- 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 WebViewuserAgent- The user agent string to use for the requestheaders- 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 aString?) and returnstrueif it's the desired resource,falseotherwisecallback- A lambda function to be invoked with the URL and headers of the matched resource.
-
-
-
-