addUserScript method
Registers userScript for injection into future documents.
This method must complete before the document is loaded. The returned opaque identifier can be passed to removeUserScript.
Implementation
Future<String> addUserScript(WebViewUserScript userScript) async {
if (userScript.source.trim().isEmpty) {
throw ArgumentError.value(
userScript.source,
'userScript.source',
'The user script source must not be empty.',
);
}
if (!await isUserScriptInjectionSupported(userScript.injectionTime)) {
throw UnsupportedError(
'${userScript.injectionTime.name} user-script injection is not '
'supported on the current platform.',
);
}
return platform.addUserScript(userScript);
}