Repository: tauri-apps/tauri (language: rust)

Issue:
[feat] `Webview::navigate` borrows `&self` instead of `&mut self`
### Describe the problem

<https://github.com/tauri-apps/tauri/blob/72748cc45cf670dd03c86c8deceb5942598f5ad9/crates/tauri/src/webview/mod.rs#L1266-L1269>

Currently, `Webview::navigate` borrows `&mut self`, but its underlying implementation [tauri_runtime::WebviewDispatch::navigate](https://docs.rs/tauri-runtime/2.3.0/tauri_runtime/trait.WebviewDispatch.html#tymethod.navigate) only requires an immutable borrow `&self`.

Is there any specific reason why `tauri::Webview` needs to do this? If not, can we change it to only require an immutable borrow `&self`?

---

## Why don't I want `&mut self`?

I am implementing Python bindings for `Webview::navigate` in pytauri: WSH032/pytauri#46.

**Python is multithreaded, and when implementing pyo3 bindings for a Rust struct, if at least one method requires `&mut self`, we have to add a thread lock, which degrades performance.**

As of now, except for `navigate`, other methods of `Webview` only require `&self`, and I don't want to add a thread lock just for only one method.

### Describe the solution you'd like

just change [WebviewWindow::navigate](https://docs.rs/tauri/latest/x86_64-pc-windows-msvc/tauri/webview/struct.WebviewWindow.html#method.navigate) and [Webview::navigate](https://docs.rs/tauri/latest/x86_64-pc-windows-msvc/tauri/webview/struct.Webview.html#method.navigate) to `&self`.

### Alternatives considered

None

### Additional context

[pyo3/Bound and interior mutability](https://pyo3.rs/v0.23.4/class.html#bound-and-interior-mutability)


Discussion / hints:

Fix patch:
diff --git a/.changes/webview-navigate-borrow-self.md b/.changes/webview-navigate-borrow-self.md
new file mode 100644
index 000000000000..f80cf726e34d
--- /dev/null
+++ b/.changes/webview-navigate-borrow-self.md
@@ -0,0 +1,5 @@
+---
+'tauri': 'minor:bug'
+---
+
+`Webview::navigate` and `WebviewWindow::navigate` borrows `&self` instead of unnecessarily borrowing `&mut self`.
diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs
index cd27e2eb259a..c5b748132693 100644
--- a/crates/tauri/src/webview/mod.rs
+++ b/crates/tauri/src/webview/mod.rs
@@ -1264,7 +1264,7 @@ fn main() {
   }
 
   /// Navigates the webview to the defined url.
-  pub fn navigate(&mut self, url: Url) -> crate::Result<()> {
+  pub fn navigate(&self, url: Url) -> crate::Result<()> {
     self.webview.dispatcher.navigate(url).map_err(Into::into)
   }
 
diff --git a/crates/tauri/src/webview/webview_window.rs b/crates/tauri/src/webview/webview_window.rs
index 901ffb1d9a47..ef7fc0f765f0 100644
--- a/crates/tauri/src/webview/webview_window.rs
+++ b/crates/tauri/src/webview/webview_window.rs
@@ -1864,7 +1864,7 @@ impl<R: Runtime> WebviewWindow<R> {
   }
 
   /// Navigates the webview to the defined url.
-  pub fn navigate(&mut self, url: Url) -> crate::Result<()> {
+  pub fn navigate(&self, url: Url) -> crate::Result<()> {
     self.webview.navigate(url)
   }
 


Test patch: