Chrome 与 Edge 浏览器历史记录解析

历史记录位置

第一步当然是找到历史记录文件啦。无论是 Chrome 还是 Edge,它们都把历史记录存在一个叫 History 的 SQLite 数据库文件中。

想知道这个文件具体位置?简单!在浏览器地址栏输入 chrome://version/ 就能看到你的配置目录路径,找到目录下的 History 数据库文件。

深入数据库结构

使用 navicat 打开这个 SQLite 数据库
250407142049447.png

我们会发现几个关键的表:

  • urls: 存储了你访问过的所有网址
  • visits: 记录了每次访问的详细信息,比如时间
  • keyword_search_terms: 保存了你的搜索记录

时间转换的小坑

研究过程中最让我头疼的是时间转换问题。Chrome/Edge 使用的是一种特殊的时间戳格式 —— 以 1601 年 1 月 1 日为起点计算的微秒数。这跟我们常见的 Unix 时间戳(1970 年起点)完全不同!

为了方便分析,我写了段 Python 代码来转换这个时间戳:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import datetime  
from datetime import timezone, timedelta


def chrome_time_to_datetime(chrome_timestamp, tz=None):
"""
将 Chrome 历史记录时间戳转换为 datetime 对象

Chrome 存储的时间是从 1601年1月1日 开始的微秒数

参数:
chrome_timestamp: Chrome 时间戳
tz: 目标时区,默认为 None (UTC) """ # Chrome 时间戳是从 1601-01-01 00:00:00 UTC 开始的微秒数
epoch_start = datetime.datetime(1601, 1, 1, tzinfo=timezone.utc)
delta = datetime.timedelta(microseconds=chrome_timestamp)
dt = epoch_start + delta

if tz:
dt = dt.astimezone(tz)

return dt


def datetime_to_chrome_time(dt):
"""
将 datetime 对象转换为 Chrome 历史记录时间戳
""" # 确保输入的 datetime 对象是 UTC 时间
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)
else:
dt = dt.astimezone(timezone.utc)

# Chrome 时间戳是从 1601-01-01 00:00:00 UTC 开始的微秒数
epoch_start = datetime.datetime(1601, 1, 1, tzinfo=timezone.utc)
delta = dt - epoch_start
return int(delta.total_seconds() * 1000000)


if __name__ == "__main__":
# 中国时区 (UTC+8) china_tz = timezone(timedelta(hours=8))

# 示例 Chrome 时间戳
chrome_timestamp = 13388148875565435

# Chrome 时间戳 -> "2025-04-03 18:58:11" dt = chrome_time_to_datetime(chrome_timestamp, china_tz)
print(f"Chrome 时间戳 {chrome_timestamp} 转换为日期时间: {dt}")

# "2025-04-03 18:58:11" -> Chrome 时间戳
dataStr = "2025-04-03 18:58:11"
now = datetime.datetime.strptime(dataStr, "%Y-%m-%d %H:%M:%S")
now = now.replace(tzinfo=china_tz) # 设置为中国时区
chrome_time = datetime_to_chrome_time(now)
print(f"当前时间 {now} 转换为 Chrome 时间戳: {chrome_time}")

格式化查询

1
2
3
4
5
6
7
8
9
10
11
12
SELECT 
v.id,
u.url,
datetime(v.visit_time/1000000 + strftime('%s', '1601-01-01'), 'unixepoch', 'localtime') AS formatted_time,
v.visit_duration
FROM
visits v
JOIN
urls u ON v.url = u.id
ORDER BY
v.visit_time DESC
LIMIT 100;

250407163150765.png

更新时间

话不多说,你懂得~

1
2
3
4
5
UPDATE visits
SET visit_time = (
(strftime('%s', '2025-04-07 18:22:12') - 8*3600 - strftime('%s', '1601-01-01')) * 1000000
)
WHERE id = 366289;

分析浏览器历史记录

待更新