diff --git a/packages/webview_flutter/webview_flutter/CHANGELOG.md b/packages/webview_flutter/webview_flutter/CHANGELOG.md index bae44ba8f51a..af796ab60073 100644 --- a/packages/webview_flutter/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.15.0 + +* Adds `WebViewController.addDocumentStartJavaScript` for injecting JavaScript + that runs at the start of future document loads. It returns a + `DocumentStartJavaScriptRegistration` that can be used to stop injecting the JavaScript. + ## 4.14.1 * Adds documentation for `NavigationDelegate` callback parameters. diff --git a/packages/webview_flutter/webview_flutter/README.md b/packages/webview_flutter/webview_flutter/README.md index d96e4443b050..cf7f9ed8ade9 100644 --- a/packages/webview_flutter/webview_flutter/README.md +++ b/packages/webview_flutter/webview_flutter/README.md @@ -61,6 +61,27 @@ See the Dartdocs for [WebViewController](https://pub.dev/documentation/webview_f and [WebViewWidget](https://pub.dev/documentation/webview_flutter/latest/webview_flutter/WebViewWidget-class.html) for more details. +### Running JavaScript at document start + +`WebViewController.addDocumentStartJavaScript` registers JavaScript that runs at the start of every +document loaded after the call, before the scripts of the loaded page run: + + +```dart +final DocumentStartJavaScriptRegistration documentStartJavaScriptRegistration = await webViewController + .addDocumentStartJavaScript( + 'window.exampleValue = "Hello from a document start script!";', + ); +``` + +The script runs in every frame of the document, including cross-origin `