You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-1Lines changed: 60 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -511,7 +511,9 @@ Does not store any data within the lifetime of the `WebView.`
511
511
512
512
#### `injectedJavaScript: string`
513
513
514
-
Specifies JavaScript that will be injected into the web page when loaded. The string should evaluate to a valid type (e.g. `true`) and not otherwise throw an exception.
514
+
Specifies JavaScript that will be injected into the web page when loaded. The string should evaluate to a valid type (e.g. `true`) and not otherwise throw an exception.
515
+
516
+
Example below passes`window.location` as a JSON object to be handled by the function passed to `onMessage`
515
517
516
518
```reason
517
519
let injectedJavaScript = "(function() {
@@ -529,6 +531,45 @@ Note that the JavaScript will only be run once when the page is loaded for the f
529
531
530
532
Refer to the [Communicating between JS and Native](https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#communicating-between-js-and-native) guide for more information.
531
533
534
+
On iOS, also refer to documentation on [WKUserScriptInjectionTimeAtDocumentEnd](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentend?language=objc).
535
+
536
+
#### `injectedJavaScriptForMainFrameOnly: bool`
537
+
538
+
_iOS only_
539
+
Script specified with `injectedJavaScript` will be loaded for all frames (main frame and iframes) when `false`, defaults to `true` (only for the main frame).
Specifies JavaScript that will be injected into the web page after the document element is created, but before any other content is loaded. The string should evaluate to a valid type (e.g. `true`) and not otherwise throw an exception.
545
+
546
+
547
+
Example below passes`window.location` as a JSON object to be handled by the function passed to `onMessage`
Refer to the [Communicating between JS and Native](https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#communicating-between-js-and-native) guide for more information.
562
+
563
+
Also refer to documentation on [WKUserScriptInjectionTimeAtDocumentStart](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentstart?language=objc).
Script specified with `injectedJavaScriptBeforeContentLoaded` will be loaded for all frames (main frame and iframes) when `false`, defaults to `true` (only for the main frame).
569
+
570
+
Note that it may not be possible to inject JS into iframes in this stage of the page lifecycle, therefore exercise caution when setting to `false`.
0 commit comments