Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
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 OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...