feat: add JavaScript scripting foundation

Introduces a JavaScript setup script that defines the `ad` helper object.
This `ad` object exposes APIs for manipulating request data, accessing response details, and managing environment variables within scripts.

Adds an `evaluate` function to execute JS code using the `flutter_js` runtime and log results or errors.
This establishes the core infrastructure for pre-request and post-response scripting.
This commit is contained in:
Udhay-Adithya
2025-04-25 22:34:02 +05:30
parent f97b39a103
commit 839d8b5c00
2 changed files with 519 additions and 0 deletions

View File

@@ -1,3 +1,6 @@
import 'dart:developer';
import 'package:flutter/services.dart';
import 'package:flutter_js/flutter_js.dart';
late JavascriptRuntime jsRuntime;
@@ -9,3 +12,12 @@ void initializeJsRuntime() {
void disposeJsRuntime() {
jsRuntime.dispose();
}
void evaluate(String code) {
try {
JsEvalResult jsResult = jsRuntime.evaluate(code);
log(jsResult.stringResult);
} on PlatformException catch (e) {
log('ERROR: ${e.details}');
}
}