Programmatically acess Google chrome history

15,747

Solution 1

You need to download the appropriate assembly from the SqLite downloads page

Once you add a reference to the SQLite assembly, its very similar to standard ADO.net

All the user history is stored in the History database located at the path in the connection string below

SQLiteConnection conn = new SQLiteConnection
    (@"Data Source=C:\Users\YourUserName\AppData\Local\Google\Chrome\User Data\Default\History");
conn.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = conn;
//  cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
//  Use the above query to get all the table names
cmd.CommandText = "Select * From urls";
SQLiteDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[1].ToString());
}

Solution 2

In Windows form application with Datagridview tool - button click event

private void button1_Click(object sender, EventArgs e)
    {
        string google = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Default\History";
        string fileName = DateTime.Now.Ticks.ToString();
        File.Copy(google, Application.StartupPath + "\\" + fileName);
        using (SQLiteConnection con = new SQLiteConnection("DataSource = " + Application.StartupPath + "\\" + fileName + ";Versio=3;New=False;Compress=True;"))
        {
            con.Open();
            //SQLiteDataAdapter da = new SQLiteDataAdapter("select url,title,visit_count,last_visit_time from urls order by last_visit_time desc", con);
            SQLiteDataAdapter da = new SQLiteDataAdapter("select * from urls order by last_visit_time desc", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            con.Close();
        }
        try // File already open error is skipped
        {
          if (File.Exists(Application.StartupPath + "\\" + fileName))
             File.Delete(Application.StartupPath + "\\" + fileName);
        }
        catch (Exception)
        {
        }
    }

Reference source

Here i have copied the History file to Application startup path in order to avoid SQLite error "database is locked".

Share:
15,747
Nithin
Author by

Nithin

Updated on June 17, 2022

Comments

  • Nithin
    Nithin almost 2 years

    I want to index all the user actions and websites in google chrome. i understand that google chrome index all the data in sqlLite database. how can i Programmatically access the chrome web history in my own application

  • Admin
    Admin about 7 years
    The database is locked exception is thrown
  • Jose Ortega
    Jose Ortega almost 7 years
    Same "The Database is locked"
  • dlopezgonzalez
    dlopezgonzalez almost 7 years
    Maybe the database is locked because an active instance of Chrome is using it, try to copy the file to another location and then read it.