Skip to content
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

v126.x (Chrome bootstrap) unable to load cookies from prior version (Alloy bootstrap) #4847

Closed
1 task done
EamonHetherton opened this issue Jun 24, 2024 · 9 comments
Closed
1 task done
Labels
faq-able! upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium.

Comments

@EamonHetherton
Copy link

EamonHetherton commented Jun 24, 2024

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

CefSharp Version

126.2.70

Operating System

Windows 11

Architecture

x64

.Net Version

net 8.0

Implementation

WinForms

Reproduction Steps

  1. Initialize CEF with a clean CachePath on a prior version of CefSharp.WinForms.NETCore (e.g. I have tested various versions from 100.0.140-125.0.210) and either create a cookie manually or visit a site that sets a cookie.
  2. update to 126.2.70 and using the same CachePath the cookie is no longer available.

Expected behavior

I would have expected that the cookie created in a prior version to still be available. I have just tested the process of upgrading the following versions and each time the cookies were still intact in the next version until I hit v126.2.70.

  • 100.0.140 -> 119.1.20
  • 119.1.20 -> 120.1.80
  • 120.1.80 -> 123.0.60
  • 123.0.60 -> 124.3.80
  • 124.3.80 -> 125.0.210
  • 125.0.210 -> 126.2.70 *no cookies

Actual behavior

no cookies appear to be in the cookie store immediately after upgrading to v126.2.70

Regression?

yes this looks like it worked in prior versions. it appears at least since 100.0.140 the cookies have been forward compatible until we reached v126.2.70

@amaitland amaitland changed the title v126.x seems to trash the cookies from prior versions v126.x unable to load cookies from prior version Jun 24, 2024
@amaitland amaitland added the upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium. label Jun 24, 2024
@amaitland
Copy link
Member

Thanks for the detailed testing 👍 It's important to remember that CefSharp is just a wrapper around the Chromium Embedded Framework(CEF).

Try switching back to the Alloy bootstrap to see if that makes a difference. Refer to #4835 (comment)

Ultimately this will need to be raised at https://github.com/chromiumembedded/cef/issues

@EamonHetherton
Copy link
Author

EamonHetherton commented Jun 24, 2024

Thanks for the prompt reply, settings.ChromeRuntime = false; does appear to fix the issue with cookies still being loadable after the update. I'll try to dig deeper into the root cause.

@EugeneSunrise
Copy link

Thanks for the prompt reply, settings.ChromeRuntime = false; does appear to fix the issue with cookies still being loadable after the update. I'll try to dig deeper into the root cause.

I had a similar problem, the point is that when we use chrome bootstrap(ChromeRuntume = true, since 125 ver.) cookies are encrypted with a key that is stored in the Local State file, but if we use alloy bootstrap cookies are encrypted with a key from LocalPrefs.json

@amaitland
Copy link
Member

Thanks for the prompt reply, settings.ChromeRuntime = false; does appear to fix the issue with cookies still being loadable after the update. I'll try to dig deeper into the root cause.

Please raise an issue on the https://github.com/chromiumembedded/cef/issues (post a link back here for reference).

We'll need to see if CEF can handle this case gracefully.

@amaitland amaitland changed the title v126.x unable to load cookies from prior version v126.x (Chrome bootstrap) unable to load cookies from prior version (Alloy bootstrap) Jun 24, 2024
@EamonHetherton
Copy link
Author

@EamonHetherton
Copy link
Author

EamonHetherton commented Jun 24, 2024

We don't plan to migrate cache directories automatically
chromiumembedded/cef#3721 (comment)
:(

I thought about trying to auto detect the first run with the Chrome bootstrap and initialise the Alloy bootstrap first and extract all the cookies, then load Chrome bootstrap and insert the cookies but can only initialise CEF once per process so that becomes significantly more difficult

@EamonHetherton
Copy link
Author

EamonHetherton commented Jun 25, 2024

some success: chromiumembedded/cef#3721 (comment)

Still not sure what to use to detect "first run" of Chrome bootstrap (probably the existence of LocalPrefs.json and not Local State file at this stage), but I think following the steps outlined in that link might work for me. Will also need to consider what other files/folders should be cleaned up as part of the Alloy->Chrome bootstrap migration.

Any thoughts on what else may need migrating?

@EamonHetherton
Copy link
Author

Work in progress migration, works for me YMMV :)

public static class Alloy_To_Chrome_Migration
{
    private static readonly string[] FoldersToMigrate = ["Cache", "Code Cache", "DawnGraphiteCache", "DawnWebGPUCache", "GPUCache", "Local Storage", "Network", "Session Storage", "Shared Dictionary"];
    private static readonly string[] FilesToMigrate = ["LOCK", "LOG", "Visited Links"];
    private const string AlloyStateFilename = "LocalPrefs.json";
    private const string ChromeStateFileName = "Local State";
    public static void Execute(CefSettings settings)
    {
        var cache_path = settings.CachePath;
        try
        {
            string alloyStateFile = Path.Combine(cache_path, AlloyStateFilename);
            string chromeStateFile = Path.Combine(cache_path, ChromeStateFileName);
            if (settings.ChromeRuntime && File.Exists(alloyStateFile) && !File.Exists(chromeStateFile))
            {
                File.Move(alloyStateFile, chromeStateFile);

                var defaultDir = Path.Combine(cache_path, "Default");
                Directory.CreateDirectory(defaultDir);

                foreach (var migrationFolderName in FoldersToMigrate)
                {
                    var migrationFolder = Path.Combine(cache_path, migrationFolderName);
                    if (Directory.Exists(migrationFolder))
                    {
                        Directory.Move(migrationFolder, Path.Combine(defaultDir, migrationFolderName));
                    }
                }
                foreach (var migrationFileName in FilesToMigrate)
                {
                    var migrationFile = Path.Combine(cache_path, migrationFileName);
                    if (File.Exists(migrationFile))
                    {
                        File.Move(migrationFile, Path.Combine(defaultDir, migrationFileName));
                    }
                }
            }
        }
        catch (Exception)
        {
        }
    }
}

@amaitland
Copy link
Member

We don't plan to migrate cache directories automatically. CEF doesn't know what Profile-specific directory you were using previously, and not all files/directories are applicable between Chrome and Alloy bootstraps.

chromiumembedded/cef#3721 (comment)

As CEF isn't going to support automatic migration, it'll be up to users to manually migrate if required.

@amaitland amaitland closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
faq-able! upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium.
Projects
None yet
Development

No branches or pull requests

3 participants