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

Issue:
Windows size returned from `webview.window().inner_size()` is incorrect
**Describe the bug**

Window size returned from `webview.window().inner_size()` does not change even if the window was resized.

I'm not sure this is actually a bug or an intended behavior. Please feel free to close this issue if it is intentional.

**Steps To Reproduce**

Clone this repository and apply the following patch.

```patch
diff --git a/examples/hello_world.rs b/examples/hello_world.rs
index f74d276..089854b 100644
--- a/examples/hello_world.rs
+++ b/examples/hello_world.rs
@@ -16,13 +16,14 @@ fn main() -> wry::Result<()> {
   let window = WindowBuilder::new()
     .with_title("Hello World")
     .build(&event_loop)?;
-  let _webview = WebViewBuilder::new(window)?
+  let webview = WebViewBuilder::new(window)?
     .with_url("https://www.netflix.com/browse")?
     // .with_incognito(true)
     .build()?;
 
   event_loop.run(move |event, _, control_flow| {
     *control_flow = ControlFlow::Wait;
+    dbg!(webview.window().inner_size());
 
     match event {
       Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
```

Then run `hello_world` example and resize the window and observe the debug prints in your terminal.

**Expected behavior**

`webview.window().inner_size()` returns the current window size.

**Screenshots**

N/A

**Platform and Versions (please complete the following information):**
OS: macOS
Rustc: `rustc 1.72.1 (d5c2e9c34 2023-09-13)`

**Would you want to assign yourself to resolve this bug?**
- [ ] Yes
- [x] No

**Additional context**

I noticed `webview.inner_size()` can return the correct size so it can be used as the replacement.


Discussion / hints:
the `tao` and `winit`'s window inner sizes are incorrect because we have to replace its NSView.
The reasons to replace it are because of keyboard accelerators and menu items. tao and winit control many keyboard handling methods. We couldn't find any better ways to handle these.
So we have `webview.inner_size()` as alternatives. Perhaps we should add documentation on why we need this method. 
Thank you @wusyong for the clarification. I'll try to add documentation for this since it was a bit surprising for me.

Fix patch:
diff --git a/src/webview/mod.rs b/src/webview/mod.rs
index cab04b443..ab0bac48b 100644
--- a/src/webview/mod.rs
+++ b/src/webview/mod.rs
@@ -513,17 +513,17 @@ impl<'a> WebViewBuilder<'a> {
   /// let window = WindowBuilder::new()
   ///   .build(&event_loop)
   ///   .unwrap();
-  ///   WebViewBuilder::new(window)
-  ///     .unwrap()
-  ///     .with_asynchronous_custom_protocol("wry".into(), |request, responder| {
-  ///       // here you can use a tokio task, thread pool or anything
-  ///       // to do heavy computation to resolve your request
-  ///       // e.g. downloading files, opening the camera...
-  ///       std::thread::spawn(move || {
-  ///         std::thread::sleep(std::time::Duration::from_secs(2));
-  ///         responder.respond(http::Response::builder().body(Vec::new()).unwrap());
-  ///       });
+  /// WebViewBuilder::new(window)
+  ///   .unwrap()
+  ///   .with_asynchronous_custom_protocol("wry".into(), |request, responder| {
+  ///     // here you can use a tokio task, thread pool or anything
+  ///     // to do heavy computation to resolve your request
+  ///     // e.g. downloading files, opening the camera...
+  ///     std::thread::spawn(move || {
+  ///       std::thread::sleep(std::time::Duration::from_secs(2));
+  ///       responder.respond(http::Response::builder().body(Vec::new()).unwrap());
   ///     });
+  ///   });
   /// ```
   #[cfg(feature = "protocol")]
   pub fn with_asynchronous_custom_protocol<F>(mut self, name: String, handler: F) -> Self
@@ -1034,6 +1034,30 @@ impl WebView {
     self.webview.is_devtools_open()
   }
 
+  /// Gets the physical size of the webview’s client area. This is
+  /// a drop-in replacement for [`Window::inner_size`] because on some platforms
+  /// (currently, only macOS), it will return an incorrect size.
+  ///
+  /// ```no_run
+  /// use wry::{
+  ///   application::{
+  ///     event_loop::EventLoop,
+  ///     window::WindowBuilder
+  ///   },
+  ///   webview::WebViewBuilder,
+  /// };
+  /// let event_loop = EventLoop::new();
+  /// let window = WindowBuilder::new().build(&event_loop).unwrap();
+  /// let webview = WebViewBuilder::new(window)
+  ///   .unwrap()
+  ///   .build()
+  ///   .unwrap();
+  ///
+  /// // This returns incorrect window size on macOS.
+  /// println!("{:?}", webview.window().inner_size());
+  /// // Instead, this always returns the correct window size.
+  /// println!("{:?}", webview.inner_size());
+  /// ```
   pub fn inner_size(&self) -> PhysicalSize<u32> {
     #[cfg(target_os = "macos")]
     {


Test patch: