Skip to content

Commit 894c283

Browse files
committed
update docs
1 parent 455194d commit 894c283

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

crates/tauri-runtime/src/webview.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,14 @@ impl WebviewAttributes {
323323
/// This is executed only on the main frame.
324324
/// If you only want to run it in all frames, use [Self::initialization_script_on_all_frames] instead.
325325
///
326-
///
327326
/// ## Platform-specific
328327
///
329-
/// - **Android on Wry:** The Android WebView does not provide an API for initialization scripts,
330-
/// so we prepend them to each HTML head. They are only implemented on custom protocol URLs.
328+
/// - **Android on Wry:** When [addDocumentStartJavaScript] is not supported,
329+
/// we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs).
330+
/// For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
331+
///
332+
/// [addDocumentStartJavaScript]: https://developer.android.com/reference/androidx/webkit/WebViewCompat#addDocumentStartJavaScript(android.webkit.WebView,java.lang.String,java.util.Set%3Cjava.lang.String%3E)
333+
/// [onPageStarted]: https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)
331334
#[must_use]
332335
pub fn initialization_script(mut self, script: &str) -> Self {
333336
self.initialization_scripts.push(InitializationScript {
@@ -347,8 +350,12 @@ impl WebviewAttributes {
347350
///
348351
/// ## Platform-specific
349352
///
350-
/// - **Android on Wry:** The Android WebView does not provide an API for initialization scripts,
351-
/// so we prepend them to each HTML head. They are only implemented on custom protocol URLs.
353+
/// - **Android on Wry:** When [addDocumentStartJavaScript] is not supported,
354+
/// we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs).
355+
/// For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
356+
///
357+
/// [addDocumentStartJavaScript]: https://developer.android.com/reference/androidx/webkit/WebViewCompat#addDocumentStartJavaScript(android.webkit.WebView,java.lang.String,java.util.Set%3Cjava.lang.String%3E)
358+
/// [onPageStarted]: https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)
352359
#[must_use]
353360
pub fn initialization_script_on_all_frames(mut self, script: &str) -> Self {
354361
self.initialization_scripts.push(InitializationScript {

crates/tauri/src/webview/mod.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,13 @@ impl<R: Runtime> WebviewBuilder<R> {
640640
/// This is executed only on the main frame.
641641
/// If you only want to run it in all frames, use [Self::initialization_script_for_all_frames] instead.
642642
///
643+
/// ## Platform-specific
644+
///
645+
/// - **Windows:** scripts are always added to subframes.
646+
/// - **Android:** When [addDocumentStartJavaScript] is not supported,
647+
/// we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs).
648+
/// For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
649+
///
643650
/// # Examples
644651
///
645652
#[cfg_attr(
@@ -669,6 +676,9 @@ fn main() {
669676
```
670677
"####
671678
)]
679+
///
680+
/// [addDocumentStartJavaScript]: https://developer.android.com/reference/androidx/webkit/WebViewCompat#addDocumentStartJavaScript(android.webkit.WebView,java.lang.String,java.util.Set%3Cjava.lang.String%3E)
681+
/// [onPageStarted]: https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)
672682
#[must_use]
673683
pub fn initialization_script(mut self, script: &str) -> Self {
674684
self
@@ -687,8 +697,14 @@ fn main() {
687697
/// Since it runs on all top-level document navigations and also child frame page navigations,
688698
/// it's recommended to check the `window.location` to guard your script from running on unexpected origins.
689699
///
690-
/// This is executed on all frames, main frame and also sub frames.
691-
/// If you only want to run it in the main frame, use [Self::initialization_script] instead.
700+
/// This is executed on all frames (main frame and also sub frames).
701+
/// If you only want to run the script in the main frame, use [Self::initialization_script] instead.
702+
///
703+
/// ## Platform-specific
704+
///
705+
/// - **Android:** When [addDocumentStartJavaScript] is not supported,
706+
/// we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs).
707+
/// For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
692708
///
693709
/// # Examples
694710
///
@@ -719,6 +735,9 @@ fn main() {
719735
```
720736
"####
721737
)]
738+
///
739+
/// [addDocumentStartJavaScript]: https://developer.android.com/reference/androidx/webkit/WebViewCompat#addDocumentStartJavaScript(android.webkit.WebView,java.lang.String,java.util.Set%3Cjava.lang.String%3E)
740+
/// [onPageStarted]: https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)
722741
#[must_use]
723742
pub fn initialization_script_for_all_frames(mut self, script: &str) -> Self {
724743
self

crates/tauri/src/webview/webview_window.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,19 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
765765
/// Adds the provided JavaScript to a list of scripts that should be run after the global object has been created,
766766
/// but before the HTML document has been parsed and before any other script included by the HTML document is run.
767767
///
768-
/// Since it runs on all top-level document navigations (and also child frame page navigations, if you set `run_only_on_main_frame` to false),
768+
/// Since it runs on all top-level document navigations,
769769
/// it's recommended to check the `window.location` to guard your script from running on unexpected origins.
770770
///
771771
/// This is executed only on the main frame.
772772
/// If you only want to run it in all frames, use [Self::initialization_script_for_all_frames] instead.
773773
///
774+
/// ## Platform-specific
775+
///
776+
/// - **Windows:** scripts are always added to subframes.
777+
/// - **Android:** When [addDocumentStartJavaScript] is not supported,
778+
/// we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs).
779+
/// For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
780+
///
774781
/// # Examples
775782
///
776783
/// ```rust
@@ -803,11 +810,18 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
803810
/// Adds the provided JavaScript to a list of scripts that should be run after the global object has been created,
804811
/// but before the HTML document has been parsed and before any other script included by the HTML document is run.
805812
///
806-
/// Since it runs on all top-level document navigastions (and also child frame page navigations, if you set `run_only_on_main_frame` to false),
813+
/// Since it runs on all top-level document navigations and also child frame page navigations,
807814
/// it's recommended to check the `window.location` to guard your script from running on unexpected origins.
808815
///
809-
/// This is executed on all frames, main frame and also sub frames.
810-
/// If you only want to run it in the main frame, use [Self::initialization_script] instead.
816+
/// This is executed on all frames (main frame and also sub frames).
817+
/// If you only want to run the script in the main frame, use [Self::initialization_script] instead.
818+
///
819+
/// ## Platform-specific
820+
///
821+
/// - **Android:** When [addDocumentStartJavaScript] is not supported,
822+
/// we prepend initialization scripts to each HTML head (implementation only supported on custom protocol URLs).
823+
/// For remote URLs, we use [onPageStarted] which is not guaranteed to run before other scripts.
824+
///
811825
/// # Examples
812826
///
813827
/// ```rust

0 commit comments

Comments
 (0)