Categories We Write About

Create a time log from browser history

Creating a time log from browser history involves extracting timestamps and visited URLs, then formatting them into a structured log. Here’s a step-by-step guide on how to do it, using Google Chrome as the browser example:


Step 1: Locate Chrome History File

If you’re using Chrome, your history is stored locally in an SQLite database file. Default locations:

  • Windows:
    C:Users<YourUsername>AppDataLocalGoogleChromeUser DataDefaultHistory

  • macOS:
    /Users/<YourUsername>/Library/Application Support/Google/Chrome/Default/History

  • Linux:
    /home/<YourUsername>/.config/google-chrome/Default/History


Step 2: Query the History Database

Use an SQLite browser or script to extract the data. Here’s a Python example:

python
import sqlite3 import datetime import os # Path to the Chrome history file (update accordingly) history_path = os.path.expanduser('~/Library/Application Support/Google/Chrome/Default/History') # Copy history file to avoid lock issues import shutil shutil.copy2(history_path, 'History_copy') # Connect to copied DB conn = sqlite3.connect('History_copy') cursor = conn.cursor() # Query visit log cursor.execute(''' SELECT urls.url, urls.title, datetime((visits.visit_time/1000000)-11644473600, 'unixepoch') as visit_time FROM visits JOIN urls ON visits.url = urls.id ORDER BY visit_time DESC ''') # Fetch and print results = cursor.fetchall() # Create time log time_log = [] for url, title, visit_time in results: time_log.append(f"{visit_time} - {title if title else url} ({url})") # Output top 20 entries as example for entry in time_log[:20]: print(entry) conn.close()

Step 3: Export as Log

To save the time log:

python
with open("browser_time_log.txt", "w", encoding="utf-8") as f: for entry in time_log: f.write(entry + "n")

Optional Enhancements

  • Group by Hour/Day: For productivity summaries.

  • Filter Specific Domains: Focus on work-related or time-wasting sites.

  • Visualize: Use libraries like matplotlib or pandas for time-based graphs.


Let me know if you’d like a version for Firefox, Edge, or a cross-platform tool with a GUI.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About