Skip to content
Open
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: The delete_cookie function incorrectly sends a WebviewMessage::SetCookie message instead of WebviewMessage::DeleteCookie, causing it to set cookies instead of deleting them.
Severity: HIGH

Suggested Fix

In the delete_cookie function, change the message being sent from WebviewMessage::SetCookie(cookie.into_owned()) to WebviewMessage::DeleteCookie(cookie.into_owned()) to match the function's intent and the corresponding message handler.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: crates/tauri-runtime-wry/src/lib.rs#L1718

Potential issue: The `delete_cookie` method in `WryWebviewDispatcher<T>` is implemented
to send a `WebviewMessage::SetCookie` message. However, the message handler has a
distinct and separate logic path for `WebviewMessage::DeleteCookie`. As a result, any
application call to `delete_cookie` will perform the opposite of its intended operation
by setting or updating the cookie instead of removing it. This breaks a fundamental
browser operation, preventing applications from clearing session data, which can have
privacy and security implications.

Did we get this right? 👍 / 👎 to inform future reviews.

),
)?;
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