addUserScript method

  1. @override
Future<void> addUserScript({
  1. required UserScript userScript,
})

Injects the specified userScript into the webpage’s content.

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • userScript: all platforms

Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.

Implementation

@override
Future<void> addUserScript({required UserScript userScript}) async {
  assert(webviewParams?.windowId == null);

  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('userScript', () => userScript.toMap());
  if (!(_userScripts[userScript.injectionTime]?.contains(userScript) ??
      false)) {
    _userScripts[userScript.injectionTime]?.add(userScript);
    await channel?.invokeMethod('addUserScript', args);
  }
}