evaluateJs method
Implementation
@override
Future evaluateJs(
String source, {
String? methodName,
bool tryPromise = true,
bool forceJsonParseResult = false,
}) async {
if (!tryPromise) {
final result = await controller?.evaluateJavascript(source: source);
if (methodName?.isNotEmpty == true) {
WhatsappLogger.log("${methodName}_Result : $result");
}
return result;
}
final String functionBody = "return await $source;";
try {
final result =
await controller?.callAsyncJavaScript(functionBody: functionBody);
final value = result?.value;
if (methodName?.isNotEmpty == true) {
WhatsappLogger.log("${methodName}_Result : $value");
}
if (result?.error != null) {
WhatsappLogger.log("${methodName}_Result_Error : ${result?.error}");
throw result!.error!;
}
if (value == "true" || value == true) return true;
if (value == "false" || value == false) return false;
return value;
} catch (e) {
WhatsappLogger.log("${methodName}_Exception : $e");
rethrow;
}
}