private IEnumerable <Cookie> GetChromeCookies()
        {
            string           cookiesPath     = GetChromeCookiesPath();
            ICookieDecryptor cookieDecryptor = new ChromeCookieDecryptor();

            // Chrome stores its cookies in an SQLite database.

            using (SQLiteConnection conn = new SQLiteConnection($"Data Source={cookiesPath}")) {
                using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Cookies", conn))
                    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd))
                        using (DataTable dt = new DataTable()) {
                            adapter.Fill(dt);

                            foreach (DataRow row in dt.Rows)
                            {
                                string name       = row["name"].ToString();
                                string value      = row["value"].ToString();
                                string domain     = row["host_key"].ToString();
                                string path       = row["path"].ToString();
                                long   expiresUtc = (long)row["expires_utc"];
                                long   isSecure   = (long)row["is_secure"];
                                long   isHttpOnly = (long)row["is_httponly"];

                                if (string.IsNullOrWhiteSpace(value))
                                {
                                    byte[] encryptedValue = (byte[])row["encrypted_value"];
                                    byte[] decryptedValue = cookieDecryptor.DecryptCookie(encryptedValue);

                                    value = Encoding.UTF8.GetString(decryptedValue);
                                }

                                // Chrome doesn't escape cookies before saving them.

                                value = Uri.EscapeDataString(value?.Trim());

                                Cookie cookie = new Cookie(name, value, path, domain)
                                {
                                    Secure   = isSecure > 0,
                                    HttpOnly = isHttpOnly > 0,
                                };

                                if (expiresUtc > 0)
                                {
                                    cookie.Expires = TimestampToDateTimeUtc(expiresUtc);
                                }

                                yield return(cookie);
                            }
                        }
            }
        }
        private static CookieContainer GetChromeWebBrowserCookies()
        {
            CookieContainer  cookies         = new CookieContainer();
            string           cookiesPath     = GetChromeCookiesPath();
            ICookieDecryptor cookieDecryptor = new ChromeCookieDecryptor();

            // Chrome stores its cookies in an SQLite database.

            using (SQLiteConnection conn = new SQLiteConnection($"Data Source={cookiesPath}")) {
                using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Cookies", conn))
                    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd))
                        using (DataTable dt = new DataTable()) {
                            adapter.Fill(dt);

                            foreach (DataRow row in dt.Rows)
                            {
                                string name   = row["name"].ToString();
                                string value  = row["value"].ToString();
                                string domain = row["host_key"].ToString();
                                string path   = row["path"].ToString();

                                if (string.IsNullOrWhiteSpace(value))
                                {
                                    byte[] encryptedValue = (byte[])row["encrypted_value"];
                                    byte[] decryptedValue = cookieDecryptor.DecryptCookie(encryptedValue);

                                    value = Encoding.UTF8.GetString(decryptedValue);
                                }

                                // Chrome doesn't escape cookies before saving them.

                                value = Uri.EscapeDataString(value?.Trim());

                                cookies.Add(new Cookie(name, value, path, domain));
                            }
                        }
            }

            return(cookies);
        }