Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

c++ - 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.

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share