How to access Google Chrome browser history programmatically on local machine How to access Google Chrome browser history programmatically on local machine google-chrome google-chrome

How to access Google Chrome browser history programmatically on local machine


It is just a SQlite 3 database, I was able to open it successfully (though of course you can't open a locked database of a running browser).


Here is a class I created to read browsing data from Google chrome. Most of the code I got from here but I tweaked it abit to add support for Google Chrome. You probably also want to download the SQLite for .Net from here and add the references to System.Data.Sqlite.

class GoogleChrome{    public List<URL> URLs = new List<URL>();    public IEnumerable<URL> GetHistory()    {        // Get Current Users App Data        string documentsFolder = Environment.GetFolderPath        (Environment.SpecialFolder.ApplicationData);        string[] tempstr = documentsFolder.Split('\\');        string tempstr1 = "";        documentsFolder += "\\Google\\Chrome\\User Data\\Default";        if (tempstr[tempstr.Length - 1] != "Local")        {            for (int i = 0; i < tempstr.Length - 1; i++)            {                tempstr1 += tempstr[i] + "\\";            }            documentsFolder =  tempstr1 + "Local\\Google\\Chrome\\User Data\\Default";        }        // Check if directory exists        if (Directory.Exists(documentsFolder))        {            return ExtractUserHistory(documentsFolder);        }        return null;    }    IEnumerable<URL> ExtractUserHistory(string folder)    {        // Get User history info        DataTable historyDT = ExtractFromTable("urls", folder);        // Get visit Time/Data info        DataTable visitsDT = ExtractFromTable("visits",        folder);        // Loop each history entry        foreach (DataRow row in historyDT.Rows)        {                // Obtain URL and Title strings                string url = row["url"].ToString();                string title = row["title"].ToString();                // Create new Entry                URL u = new URL(url.Replace('\'', ' '),                title.Replace('\'', ' '),                "Google Chrome");                // Add entry to list                URLs.Add(u);        }        // Clear URL History        DeleteFromTable("urls", folder);        DeleteFromTable("visits", folder);        return URLs;    }    void DeleteFromTable(string table, string folder)    {        SQLiteConnection sql_con;        SQLiteCommand sql_cmd;        // FireFox database file        string dbPath = folder + "\\History";        // If file exists        if (File.Exists(dbPath))        {            // Data connection            sql_con = new SQLiteConnection("Data Source=" + dbPath +            ";Version=3;New=False;Compress=True;");            // Open the Conn            sql_con.Open();            // Delete Query            string CommandText = "delete from " + table;            // Create command            sql_cmd = new SQLiteCommand(CommandText, sql_con);            sql_cmd.ExecuteNonQuery();            // Clean up            sql_con.Close();        }    }    DataTable ExtractFromTable(string table, string folder)    {        SQLiteConnection sql_con;        SQLiteCommand sql_cmd;        SQLiteDataAdapter DB;        DataTable DT = new DataTable();        // FireFox database file        string dbPath = folder + "\\History";        // If file exists        if (File.Exists(dbPath))        {            // Data connection            sql_con = new SQLiteConnection("Data Source=" + dbPath +            ";Version=3;New=False;Compress=True;");            // Open the Connection            sql_con.Open();            sql_cmd = sql_con.CreateCommand();            // Select Query            string CommandText = "select * from " + table;            // Populate Data Table            DB = new SQLiteDataAdapter(CommandText, sql_con);            DB.Fill(DT);            // Clean up            sql_con.Close();        }        return DT;    }}

The class for the URL:

class URL{    string url;    string title;    string browser;    public URL(string url, string title, string browser)    {        this.url = url;        this.title = title;        this.browser = browser;    }    public string getData()    {        return browser + " - " + title + " - " + url;    }}

It worked like a charm for me. Hope it helps


For viewing sqlite databases (which is what the Chromium history index is), I've preferred sqlitebrowser. It's free and works on Windows, Mac, and Linux. An all-time fave for me.