feat: add WebView::set_cookie and WebView::delete_cookie#13661
feat: add WebView::set_cookie and WebView::delete_cookie#13661lucasfernog merged 6 commits intotauri-apps:devfrom
WebView::set_cookie and WebView::delete_cookie#13661Conversation
Package Changes Through 1511888There are 10 changes which include tauri with minor, tauri-cli with minor, @tauri-apps/cli with minor, tauri-utils with minor, tauri-bundler with minor, tauri-macos-sign with minor, tauri-runtime-wry with minor, tauri-runtime with minor, @tauri-apps/api with minor, tauri-plugin with minor Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
WSH032
left a comment
There was a problem hiding this comment.
This PR is ready, but it needs to wait for the Wry PR to be merged and for Tauri to upgrade the Wry version.
| WebviewMessage::SetCookie(cookie) => { | ||
| if let Err(e) = webview.set_cookie(&cookie) { | ||
| log::error!("failed to set webview cookie: {e}"); | ||
| } | ||
| } | ||
|
|
||
| WebviewMessage::DeleteCookie(cookie) => { | ||
| if let Err(e) = webview.delete_cookie(&cookie) { | ||
| log::error!("failed to delete webview cookie: {e}"); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I have some questions. Why do some methods use a channel to wait for a Result<()> to return, while others simply ignore (log) errors?
|
Oops, something went wrong on Linux. Should we enable |
|
Waiting for this to be merged. Cant wait to test it out ❤️ |
WSH032
left a comment
There was a problem hiding this comment.
Also, I think we should re-export cookie crate at mod webview, otherwise users won't be able to construct Cookie instances directly.
| Message::Webview( | ||
| *self.window_id.lock().unwrap(), | ||
| self.webview_id, | ||
| WebviewMessage::DeleteCookie(cookie.clone().into_owned()), |
There was a problem hiding this comment.
The cookie.clone() here was forgotten to be removed.
| use serde::Serialize; | ||
| use tauri_macros::default_runtime; | ||
| pub use tauri_runtime::webview::{NewWindowFeatures, PageLoadEvent}; | ||
| pub use tauri_runtime::Cookie; |
There was a problem hiding this comment.
We used to expose this as a public API. Wouldn't removing it cause some issues?
There was a problem hiding this comment.
Yeah, we should probably bring it back
Edit: done in #14020
|
I have this function that I've made and I try to delete the session cookie. The use case is that I make an account manager and I need to handle sessions on multiple roblox accounts. The code successfully enters in the if statement but the delete_cookie doesnt seem to actually delete it. I refresh the page, I run the command multiple times and it simply does not work. Does anyone has any ideeas why this might be the case? #[tauri::command]
async fn delete_session(window: tauri::WebviewWindow) {
let cookies = window.cookies().unwrap();
for cookie in cookies {
if cookie.name() == ".ROBLOSECURITY" {
println!("{:?}", cookie);
window.delete_cookie(cookie).unwrap();
println!("Deleted .ROBLOSECURITY cookie");
}
}
window.eval("window.location.replace('https://www.roblox.com/')").unwrap();
} |
ref #12665
wry pr tauri-apps/wry#1569