runJavaScript method
Runs the given JavaScript in the context of the current page.
The Future completes with an error if a JavaScript error occurred.
Implementation
@override
Future<void> runJavaScript(String javaScript) async {
final iDocument = _webWebViewParams.iFrame.contentDocument;
final iBody = iDocument?.body;
if (iDocument == null || iBody == null) {
// WebWebViewWidget will call me later.
_javaScript = javaScript;
} else {
/// Reset iScript.
if (_iScript != null) {
iBody.removeChild(_iScript!);
}
_iScript = iDocument.createElement('script') as web.HTMLScriptElement;
iBody.appendChild(_iScript!);
/// Inject JavaScript. Data URL to work around strict CSP.
_iScript!.src = Uri.dataFromString(
javaScript,
mimeType: 'text/javascript',
encoding: utf8,
).toString();
}
}