Programmatically acess Google chrome history Programmatically acess Google chrome history sqlite sqlite

Programmatically acess Google chrome history


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 namescmd.CommandText = "Select * From urls";SQLiteDataReader dr = cmd.ExecuteReader();while (dr.Read()){Console.WriteLine(dr[1].ToString());}


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".


Used below code getting "Windows/x86_64" as a result

   try    {        Class.forName ("org.sqlite.JDBC");        connection = DriverManager.getConnection ("jdbc:sqlite:/C:/Users/tarun.kakkar/AppData/Local/Google/Chrome/User Data/Default/History");        statement = connection.createStatement ();        resultSet = statement.executeQuery ("SELECT * FROM urls");        while (resultSet.next ())         {            System.out.println ("URL [" + resultSet.getString ("url") + "]" + ", visit count [" + resultSet.getString ("visit_count") + "]");        }    }     catch (Exception e)     {        e.printStackTrace ();    }