removeUserScriptsByGroupName method
Removes all the UserScript
s with groupName
as group name from the webpage’s content.
User scripts already loaded into the webpage's content cannot be removed. This will have effect only on the next page load.
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:
- Android native WebView
- iOS
- MacOS
- Windows
Implementation
@override
Future<void> removeUserScriptsByGroupName({required String groupName}) async {
final List<UserScript> userScriptsAtDocumentStart = List.from(
_userScripts[UserScriptInjectionTime.AT_DOCUMENT_START] ?? []);
for (final userScript in userScriptsAtDocumentStart) {
if (userScript.groupName == groupName) {
_userScripts[userScript.injectionTime]?.remove(userScript);
}
}
final List<UserScript> userScriptsAtDocumentEnd =
List.from(_userScripts[UserScriptInjectionTime.AT_DOCUMENT_END] ?? []);
for (final userScript in userScriptsAtDocumentEnd) {
if (userScript.groupName == groupName) {
_userScripts[userScript.injectionTime]?.remove(userScript);
}
}
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('groupName', () => groupName);
await channel?.invokeMethod('removeUserScriptsByGroupName', args);
}