Skip to content

[Problem/Bug]: Workaround to clear partioned cookies no longer works #5185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pushkin- opened this issue Mar 31, 2025 · 5 comments
Closed

[Problem/Bug]: Workaround to clear partioned cookies no longer works #5185

pushkin- opened this issue Mar 31, 2025 · 5 comments
Assignees
Labels
bug Something isn't working regression Something used to work but doesn't anymore

Comments

@pushkin-
Copy link

What happened?

Due to this issue, we're using the workaround suggested here to delete partioned cookies.

This workaround used to work, but recently stopped.
This broke some time between Aug 27, 2024 (runtime 126 or 127) and 3/20/2025 (runtime 134)

Seems like this API is broken now:
https://chromedevtools.github.io/devtools-protocol/tot/Storage/#method-clearDataForOrigin

If we can't reliably use this workaround, then it's important for our app to have #4669 fixed

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

136.0.3227.0-canary, 134

SDK Version

3116.0

Framework

Winforms

Operating System

Windows 11

OS Version

26100.3476

Repro steps

Download the WinForms WebView2 sample app and build for .net 8 (to get access to System.Text.Json)
In BrowserForm.cs, change the HandleWebMessage to:

async void HandleWebMessage(CoreWebView2WebMessageReceivedEventArgs args, CoreWebView2Frame frame = null)
{
  if (args.WebMessageAsJson.Contains("AAA"))
    {
      var cm = this.webView2Control.CoreWebView2.CookieManager;
      Dictionary<string, string> clearDataParams = new Dictionary<string, string>() {
        { "origin", "" },
        { "storageTypes", "cookies" }
      };
    foreach (CoreWebView2Cookie cookie in await cm.GetCookiesAsync(null))
    {
       if (cookie.Domain == "the-domain-you're-test")
         {
            cm.DeleteCookie(cookie);
            clearDataParams["origin"] = new UriBuilder(cookie.IsSecure ? "https" : "http", cookie.Domain, -1, cookie.Path).Uri.ToString();
            await this.webView2Control.CoreWebView2.CallDevToolsProtocolMethodAsync("Storage.clearDataForOrigin", JsonSerializer.Serialize(clearDataParams));
         }
      }
  }
}
  1. start app
  2. Select Scenario menu item and click Web Message
  3. Open devtools and replace the frame with some site that sets a partioned cookie
  4. Then run the code window.chrome.webview.postMessage("AAA")
  5. You can set a breakpoint and see that the deletion code is running
  6. Go to Application -> Cookies -> third party site and notice that the cookie hasn't been deleted

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Regression in newer Runtime

Last working version (if regression)

127

@pushkin- pushkin- added the bug Something isn't working label Mar 31, 2025
@github-actions github-actions bot added the regression Something used to work but doesn't anymore label Mar 31, 2025
@pushkin-
Copy link
Author

pushkin- commented Apr 1, 2025

This seems to have broken between Chromium version 132.0.6834.210 and 133.0.6920.0

@pushkin-
Copy link
Author

pushkin- commented Apr 3, 2025

Looking through all the commits between those two chromium versions, this one stood out as being suspicious: https://chromium.googlesource.com/chromium/src/+/ef0eba18e45cbafff9f351b280d780fdb0f2a012

Maybe the partitioned cookie isn't being deleted due to that extra filtering logic that got added.

@ParadoxZero
Copy link

@pushkin-
Copy link
Author

@ParadoxZero Thanks! It seems to work. Maybe because we are forced to pass in a partition key into deleteCookies, so the filtering code that was added can find the right cookie to delete.

@pushkin-
Copy link
Author

Reported here https://issues.chromium.org/issues/408248571
Will close this since it's a Chromium regression and we have a workaround for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Something used to work but doesn't anymore
Projects
None yet
Development

No branches or pull requests

3 participants