Skip to content

feat(windows): add with_profile_name for WebView2 multi-profile support#1738

Merged
Legend-Master merged 1 commit into
tauri-apps:devfrom
Glint-Software:glint/with-profile-name
May 27, 2026
Merged

feat(windows): add with_profile_name for WebView2 multi-profile support#1738
Legend-Master merged 1 commit into
tauri-apps:devfrom
Glint-Software:glint/with-profile-name

Conversation

@jtbourke
Copy link
Copy Markdown
Contributor

Adds WebViewBuilderExtWindows::with_profile_name so embedded webviews can opt into a named WebView2 profile, isolating cookies, storage, IndexedDB, and cache from the host app's default profile while sharing the same WebView2 environment/runtime.

Motivation

A common use case for wry (and Tauri downstream) is hosting an in-app browser tab alongside the main app webview. Without profile isolation, both share the unnamed default profile under the same user_data_folder, which means anything a user does in the embedded browser (signing into github.com, storing cookies, etc.) is mixed with the host app's own localStorage state. Profile-wide operations like clearing browsing data become unsafe because they touch the host app's storage as collateral damage.

with_data_directory (separate user_data_folder) is the existing workaround but it creates an entirely separate WebView2 environment with its own runtime/networking stack — which has historically caused OAuth/login-page regressions in apps that tried it (downstream report: Glint #2665).

Microsoft's recommended multi-profile pattern (https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/multi-profile-support) is named profiles within a shared environment, which ICoreWebView2ControllerOptions::SetProfileName enables. This PR exposes it through wry.

Changes

  • New profile_name: Option<String> field on the Windows PlatformSpecificWebViewAttributes.
  • New trait method on WebViewBuilderExtWindows: with_profile_name<S: Into<String>>(self, name: S) -> Self.
  • In create_controller, when a profile name is configured, call ICoreWebView2ControllerOptions::SetProfileName before CreateCoreWebView2ControllerWithOptions.

When with_profile_name is not called the behavior is unchanged — the webview uses the unnamed default profile, same as today.

Platform notes

This PR only touches Windows. macOS / iOS already have with_data_store_identifier for the equivalent functionality. A follow-up could add the Linux equivalent (a dedicated WebsiteDataManager directory) under a unified API name if there's appetite for that.

Naming-rule notes

WebView2 enforces profile-name rules (alphanumeric + ., _, -, space; up to 64 chars; cannot start or end with . or space). The doc-comment on with_profile_name mentions these constraints. The patch doesn't validate the string client-side — SetProfileName returns an error for malformed names, which is surfaced as a wry::Error at build time.

Related

@jtbourke jtbourke requested a review from a team as a code owner May 25, 2026 23:38
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Package Changes Through 2a081b9

There are 1 changes which include wry with minor

Planned Package Versions

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

package current next
wry 0.55.1 0.56.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

Legend-Master
Legend-Master previously approved these changes May 26, 2026
Copy link
Copy Markdown
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

Comment thread src/webview2/mod.rs Outdated
…port

Adds `WebViewBuilderExtWindows::with_profile_name(name)` so embedded
webviews can opt into a named WebView2 profile. Webviews with different
profile names within the same environment have isolated cookies, storage,
IndexedDB, and cache while sharing the runtime — matching WebView2's
documented multi-profile pattern. When unset, behavior is unchanged
(unnamed default profile).

Implementation:
- New `profile_name: Option<String>` field on the Windows
  `PlatformSpecificWebViewAttributes`.
- New trait method on `WebViewBuilderExtWindows`.
- In `create_controller`, when a profile name is configured, call
  `ICoreWebView2ControllerOptions::SetProfileName` before
  `CreateCoreWebView2ControllerWithOptions`.

Profile names must follow WebView2's naming rules (alphanumeric, `.`,
`_`, `-`, ` `, up to 64 chars, not starting/ending with `.` or ` `).

See https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/multi-profile-support
@jtbourke jtbourke force-pushed the glint/with-profile-name branch from 44239c3 to 2a081b9 Compare May 26, 2026 15:21
Copy link
Copy Markdown
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

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

Thanks!

@Legend-Master Legend-Master merged commit 10fdf73 into tauri-apps:dev May 27, 2026
20 checks passed
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.

Support for Browser Profiles (extension of Tauri issue #9285)

2 participants