addUserScript method

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

Injects the specified userScript into the webpage’s content.

NOTE for iOS and MacOS: this method will throw an error if the PlatformWebViewCreationParams.windowId has been set. There isn't any way to add/remove user scripts specific to window WebViews. This is a limitation of the native WebKit APIs.

Officially Supported Platforms/Implementations:

Implementation

@override
Future<void> addUserScript({required UserScript userScript}) async {
  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);
  }
}