How to disable the SameSite Cookies policy in Cefsharp

By FoxLearn 6/29/2024 2:17:06 AM   84
To disable the SameSite Cookies policy in CefSharp, you typically need to adjust the underlying Chromium settings.

Here’s how to disable the SameSite Cookies policy in Cefsharp

By default, when running the latest version of CefSharp

ceftsharp

If your application requires handling cookies in a manner that disables the SameSite policy by default in CefSharp, you can achieve this by configuring the CefSettings object during the browser initialization.

Modify the CefSettings object to disable the SameSiteByDefaultCookies feature.

var settings = new CefSettings();
// Initialize other settings as needed
// Disable SameSiteByDefaultCookies to allow cross-site cookies
settings.CefCommandLineArgs.Add("disable-features", "SameSiteByDefaultCookies");

// Initialize CefSharp with customized settings
Cef.Initialize(settings);

This approach ensures that the SameSite policy for cookies is disabled by default, catering to specific application requirements that necessitate legacy handling of cookies.

After initializing CefSharp with the SameSiteByDefaultCookies feature disabled using the CefSettings object, cross-site cookies will now be set differently in your application.

cefsharp setting

You can also append the name of the feature at the end of the disable-features key.

settings.CefCommandLineArgs["disable-features"] += ",SameSiteByDefaultCookies";

After launching your application and revisiting the tool page, you will notice that cookies in the cross-site column are now properly set.