inappwebview_script_guard 0.1.1 copy "inappwebview_script_guard: ^0.1.1" to clipboard
inappwebview_script_guard: ^0.1.1 copied to clipboard

Detect silently-failed JavaScript injection in flutter_inappwebview: canary-verified script loading plus commit-time AST linting of embedded JS.

example/example.md

inappwebview_script_guard example #

import 'dart:convert';

import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:inappwebview_script_guard/inappwebview_script_guard.dart';

/// A literal script: raw triple-quoted string, no interpolation.
final probeScript = JsScript(
  name: 'probe',
  source: r'''
JSON.stringify((function () {
  return {title: document.title, blocks: document.querySelectorAll('p').length};
})());
''',
);

Future<void> runProbe(InAppWebViewController controller) async {
  final (canary, bridgeRaw) =
      await injectAndVerifyCanary(controller, probeScript);

  switch (canary) {
    case LoadedResult():
      final payload = jsonDecode(bridgeRaw as String) as Map<String, dynamic>;
      print('probe ok: $payload');
    case MissingResult():
      print('script-side failure (parse error / mid-run throw): $canary');
    case InjectThrewResult(:final exception):
      print('bridge-side failure: $exception');
    case StaleResult():
      print('cached older script running — reload the page: $canary');
    case MalformedResult():
      print('flag clobbered by other JS — investigate: $canary');
  }
}

The commit-time tooling is wired separately — see the README's "Git-hook wiring" section and the scripts in example/hooks/.

0
likes
150
points
13
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Detect silently-failed JavaScript injection in flutter_inappwebview: canary-verified script loading plus commit-time AST linting of embedded JS.

Repository (GitHub)
View/report issues

Topics

#webview #javascript #injection #observability

License

MIT (license)

Dependencies

analyzer, crypto, flutter, flutter_inappwebview

More

Packages that depend on inappwebview_script_guard