Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
Message::Webview(
*self.window_id.lock().unwrap(),
self.webview_id,
WebviewMessage::DeleteCookie(cookie.clone().into_owned()),
WebviewMessage::SetCookie(cookie.into_owned()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Bug: delete_cookie sends SetCookie message — deletes become sets

The delete_cookie dispatch function (line 1712-1722) now sends WebviewMessage::SetCookie instead of WebviewMessage::DeleteCookie. This means every call to delete_cookie() will set the cookie instead of deleting it — the exact opposite of the intended behavior.

The message handler side is correct (DeleteCookie handler calls webview.delete_cookie()), but the message is never dispatched because delete_cookie() routes through SetCookie instead.

This was introduced by changing WebviewMessage::DeleteCookie(cookie.clone().into_owned()) to WebviewMessage::SetCookie(cookie.into_owned()). While removing the unnecessary .clone() was a good fix, the message variant was also changed incorrectly.

Impact: Any application using Webview::delete_cookie() will silently set the cookie instead of deleting it. This is a data integrity / privacy issue — cookies that users or the application expect to be deleted will persist.

Was this helpful? React with 👍 / 👎

Suggested change
WebviewMessage::SetCookie(cookie.into_owned()),
WebviewMessage::DeleteCookie(cookie.into_owned()),
  • Apply suggested fix

),
)?;
Ok(())
Expand Down
5 changes: 3 additions & 2 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
pub(crate) mod plugin;
mod webview_window;

use cookie::Cookie;
pub use webview_window::{WebviewWindow, WebviewWindowBuilder};

/// Cookie crate used for [`Webview::set_cookie`] and [`Webview::delete_cookie`].
Expand All @@ -20,6 +19,8 @@ use http::HeaderMap;
use serde::Serialize;
use tauri_macros::default_runtime;
pub use tauri_runtime::webview::{NewWindowFeatures, PageLoadEvent};
// Remove this re-export in v3
pub use tauri_runtime::Cookie;
#[cfg(desktop)]
use tauri_runtime::{
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
Expand Down Expand Up @@ -521,7 +522,7 @@ tauri::Builder::default()
"opened-window",
tauri::WebviewUrl::External("about:blank".parse().unwrap()),
)
.with_window_features(features)
.window_features(features)
.on_document_title_changed(|window, title| {
window.set_title(&title).unwrap();
})
Expand Down
12 changes: 6 additions & 6 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
/// "opened-window",
/// tauri::WebviewUrl::External("about:blank".parse().unwrap()),
/// )
/// .with_window_features(features)
/// .window_features(features)
/// .on_document_title_changed(|window, title| {
/// window.set_title(&title).unwrap();
/// })
Expand Down Expand Up @@ -1312,13 +1312,13 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
target_os = "netbsd",
target_os = "openbsd"
))]
pub fn with_window_features(mut self, features: NewWindowFeatures) -> Self {
if let Some(position) = features.position() {
self.window_builder = self.window_builder.position(position.x, position.y);
pub fn window_features(mut self, features: NewWindowFeatures) -> Self {
if let Some(size) = features.size() {
self.window_builder = self.window_builder.inner_size(size.width, size.height);
}

if let Some(size) = features.size() {
self.window_builder = self.window_builder.inner_size(size.width, size.height);
if let Some(position) = features.position() {
self.window_builder = self.window_builder.position(position.x,position.y);
}

#[cfg(target_os = "macos")]
Expand Down
48 changes: 23 additions & 25 deletions examples/api/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ mod menu_plugin;
#[cfg(desktop)]
mod tray;

use std::sync::atomic::AtomicUsize;

use serde::Serialize;
use tauri::{
ipc::Channel,
Expand Down Expand Up @@ -68,40 +66,40 @@ pub fn run_app<R: Runtime, F: FnOnce(&App<R>) + Send + 'static>(
.build()?,
));

let app_ = app.handle().clone();

let mut created_window_count = AtomicUsize::new(0);
let mut window_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
.on_new_window(move |url, features| {
println!("new window requested: {url:?} {features:?}");

let number = created_window_count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);

let builder = tauri::WebviewWindowBuilder::new(
&app_,
format!("new-{number}"),
tauri::WebviewUrl::External("about:blank".parse().unwrap()),
)
.with_window_features(features)
.on_document_title_changed(|window, title| {
window.set_title(&title).unwrap();
})
.title(url.as_str());

let window = builder.build().unwrap();
tauri::webview::NewWindowResponse::Create { window }
})
.on_document_title_changed(|_window, title| {
println!("document title changed: {title}");
});

#[cfg(all(desktop, not(test)))]
{
let app_ = app.handle().clone();
let mut created_window_count = std::sync::atomic::AtomicUsize::new(0);

window_builder = window_builder
.title("Tauri API Validation")
.inner_size(1000., 800.)
.min_inner_size(600., 400.)
.menu(tauri::menu::Menu::default(app.handle())?);
.menu(tauri::menu::Menu::default(app.handle())?)
.on_new_window(move |url, features| {
println!("new window requested: {url:?} {features:?}");

let number = created_window_count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);

let builder = tauri::WebviewWindowBuilder::new(
&app_,
format!("new-window-{number}"),
tauri::WebviewUrl::External("about:blank".parse().unwrap()),
)
.window_features(features)
.on_document_title_changed(|window, title| {
window.set_title(&title).unwrap();
})
.title(url.as_str());

let window = builder.build().unwrap();
tauri::webview::NewWindowResponse::Create { window }
});
}

let webview = window_builder.build()?;
Expand Down