Kitiara
Kitiara

Reputation: 498

How to set tab based cookies in WebView2?

How can I set a cookie which would be applicable for just a specific tab in the browser ? Chrome keeps cookies separated for normal mode and incognito mode. What i'm trying to achieve is similar to this but i want to do that for every tab in normal mode.

Upvotes: 1

Views: 339

Answers (1)

Poul Bak
Poul Bak

Reputation: 10940

If I understand correctly, you have a tab based application with a WebView2 on each tab and you want a separate environment for each WebView2 so they have their own cookies.

There's an example of setting up an environment here: Getting started with WebView2 Go to Step 3.

The second argument to CreateCoreWebView2EnvironmentWithOptions is the userdatafolder. This must be unique to each tab.

You can for instance create a random folder name or add the tab index to the folder name.

Now the webview2 controls will have their own environment, including cache and cookies.

Upvotes: 2

Related Questions