How to prevent the web page to read or write cookies in WebView2

Lan Zuo 1 Reputation point
2024-05-01T10:18:02.0666667+00:00

I'm trying to write to program with webview2, the control document is here:

https://learn.microsoft.com/en-us/microsoft-edge/webview2/

The WebView2.CoreWebView2.CookieManager provides lots of methods to read/write cookies, but this is not what I want.

I want to know when the webview2 web page reads/writes the cookies on my disk, or disable cookie read/write for specified site.

For example, I'm the user that use a program with webview2 to navigate www sites, and I know www.microsoft.com is friendly to me, so I allow this site to write/read cookies in my disk, so I add it into the whitelist. And I also know www.buygoodsfoo.com will peek what I had buy from internet through cookies, and may push ADs to me, so I won't let it read/write cookies on my disk, then I can add it in the blacklist.

So there is a requirements, that I need to prevents specified site to read/write cookes in webview2 program, or when the site attempt to read/write cookies, the object control could raise up an event, so I can write some code to do such work in the event callback, cancel it or pass it.

who can tell me the way?

Thanks very much.

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,162 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,352 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 57,641 Reputation points
    2024-05-01T16:16:26.1566667+00:00
    0 comments No comments