Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tauri::Webview::cookies_by_url() and tauri::Cookie #12665

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

charrondev
Copy link

@charrondev charrondev commented Feb 9, 2025

Closes

Related

Related issues not fully handled by this PR:

Changes

  • Added Webview::cookies_for_url() and tauri::Cookie

Implementation notes

I'm open to any requested changes here, but here's how I've gone about this:

  • Expose cookie::Cookie as a re-export from tauri_runtime::Cookie and tauri::Cookie. Notably I did not re-export the wry::Cookie which is a re-export of cookie::Cookie since tauri_runtime does not have a dependency on wry.
  • Add cookies_for_url() on the webview dispatcher and add an implementation for wry. I used WebviewDispatcher::reparent as my template for a dispatch the takes a parameter and returns a result.
  • I chose not to expose wry::webview::cookies() as it seemed to have an implementation note that it didn't work on Android at the moment.

Notes from my testing

Notably the wry support seems to only work when a site served over http (which is what I need it for). In my manual testing there doesn't seem to be a clear story for cookies on the tauri:// protocol (and there probably shouldn't be?). In any case by linking this PR into my own project I am able to extract the cookies from content served over http/https.

@charrondev charrondev requested a review from a team as a code owner February 9, 2025 19:26
@charrondev charrondev force-pushed the feat/cookies-for-url branch from e2ca406 to bccd107 Compare February 9, 2025 19:32
Copy link
Contributor

github-actions bot commented Feb 9, 2025

Package Changes Through fdbefdd

There are 8 changes which include tauri with minor, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-cli with minor, tauri-utils with minor, @tauri-apps/api with minor, @tauri-apps/cli with minor, tauri-bundler with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.2.0 2.3.0
tauri-utils 2.1.1 2.2.0
tauri-bundler 2.2.3 2.2.4
tauri-runtime 2.3.0 2.4.0
tauri-runtime-wry 2.3.0 2.4.0
tauri-codegen 2.0.4 2.0.5
tauri-macros 2.0.4 2.0.5
tauri-plugin 2.0.4 2.0.5
tauri-build 2.0.5 2.0.6
tauri 2.2.5 2.3.0
@tauri-apps/cli 2.2.7 2.3.0
tauri-cli 2.2.7 2.3.0

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Copy link
Member

@FabianLars FabianLars left a comment

Choose a reason for hiding this comment

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

thank you!!

I chose not to expose wry::webview::cookies() as it seemed to have an implementation note that it didn't work on Android at the moment.

It would be fine to do the same in tauri as well (having this function return an empty vec with a platform-specific note)

@@ -1157,6 +1158,11 @@ impl<R: Runtime> Webview<R> {
Ok(())
}

/// Returns all cookies for a specified URL including HTTP-only and secure cookies.
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a note about the scheme requirements here? imo quite important

Copy link
Author

Choose a reason for hiding this comment

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

I've added a note. This actually seems more of a bug/runtime limitation than anything. I would imagine this is because the tauri:// protocol behaves like the the file:// protocol in browsers and doesn't actually expose a functional cookie store.

@charrondev
Copy link
Author

I've added the relevant note and the cookies() function.

I've also gone in and fixed up my fustfmt and clippy issues.

@charrondev
Copy link
Author

As I'm testing this more deeply, I'm finding some concerning going. Fetching cookies is occasionally hanging the entire process. I will try to dig in some more.

@charrondev
Copy link
Author

So after testing a bit more I've narrowed down the source of the hangs. It seems to happen in the MacOS implemenation specifically getting caught up in wry's wait_for_blocking_operation().

https://github.com/tauri-apps/wry/blob/cf181943444bca172d969615471997e48e10b611/src/wkwebview/mod.rs#L1057-L1077

I've gone and made a PR over on wry to resolve it tauri-apps/wry#1486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants