WebView API
Description
IWebViewAPI is designed for interacting with WebView inside Android applications in ZennoDroid. It allows you to execute JavaScript code, retrieve connection information, and manage certificates.
Methods
DisableForcedRenderWebView
-
void DisableForcedRenderWebView()
Reverts the patch applied byEnableForcedRenderWebView.Description:
Restores Chromium's defaultAutoDisableAccessibilityV2behavior, allowing the browser to shut down the accessibility tree when no screen readers are connected.
Example
var webView = instance.DroidInstance.WebView;
webView.DisableForcedRenderWebView(); // Restore the default element tree behaviour
EnableForcedRenderWebView
-
void EnableForcedRenderWebView()
Forces the Chromium accessibility tree to remain active.Description:
Bypasses Chromium'sAutoDisableAccessibilityV2feature, which automatically shuts down the accessibility tree when no screen readers (such as TalkBack) are detected as active. Call this method before interacting with WebView elements via Appium if elements are not being found.
Example
var webView = instance.DroidInstance.WebView;
webView.EnableForcedRenderWebView(); // Turn on element tree rendering
var html = webView.EvaluateScript("return document.body.innerHTML;");
webView.DisableForcedRenderWebView(); // Restore the default behaviour
EvaluateScript
-
string EvaluateScript(string script)
Executes JavaScript code inside WebView.Parameters:
script— JavaScript code to execute.
Returns:
The result of the script execution as a string.
Example
var webView = instance.DroidInstance.WebView;
var html = webView.EvaluateScript("return document.body.innerHTML;"); // Run JavaScript in the WebView
var title = webView.EvaluateScript("return document.title;");
GetAttachedWebSocketUrl
-
string GetAttachedWebSocketUrl()
Retrieves the WebSocket connection URL.Returns:
A string containing the WebSocket address.Description:
Used for debugging and analyzing WebView connections (e.g. for attaching DevTools).
Example
var webView = instance.DroidInstance.WebView;
var url = webView.GetAttachedWebSocketUrl(); // WebSocket address of the active WebView page
project.SendInfoToLog(url);
InjectSystemCertificate
-
void InjectSystemCertificate(string source)
Installs a system certificate.Parameters:
source— path to the certificate or its contents.
Description:
Allows adding a trusted certificate to the system for:- intercepting HTTPS traffic;
- working with proxies (Burp, Charles, Fiddler);
- bypassing SSL pinning (in some cases).
Example
var webView = instance.DroidInstance.WebView;
webView.InjectSystemCertificate(project.Variables["cert_pem"].Value);