browser.rb 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +52 -0
- data/README.md +18 -3
- data/Rakefile +19 -7
- data/lib/Browser/ChromiumBased.rb +5 -0
- data/lib/Browser/FirefoxBased.rb +10 -1
- data/lib/Browser/History.rb +23 -5
- data/lib/Browser/Safari.rb +10 -1
- data/lib/Browser/VERSION.rb +1 -1
- data/lib/Browser/Visit.rb +29 -0
- data/test/Browser/Brave_test.rb +3 -3
- data/test/Browser/Chrome_test.rb +3 -3
- data/test/Browser/Chromium_test.rb +11 -3
- data/test/Browser/Firefox_test.rb +21 -3
- data/test/Browser/Safari_test.rb +21 -4
- data/test/Browser/TorBrowser_test.rb +3 -3
- data/test/Browser/Visit_test.rb +44 -0
- data/test/fixtures/FirefoxBased_places.sqlite +0 -0
- data/test/fixtures/Safari_history.sqlite +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a736546223df5f12913619dac1b903777955ea041b4ee806bfa1bd3b09ab3a4b
|
|
4
|
+
data.tar.gz: a0d4448f4e869e97dfb4f73af4faadeb3c60ac6e48a18c6c0e57806fe815376e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9439088a3a40be8275d04a5f415300c7cfbbcaa6db69eb7c3c4e3a658d40c0e81a3401aa310894a10471715d2659585c7bd3da4ff4777227240f2598de439fd3
|
|
7
|
+
data.tar.gz: bd4ae380165c93fd78ab013e4e6f5ed244097b09fb68347bee13874f30573ee6027317c8cccf57cb66c9995654d0250826e3eab1fb542ebd6eaf44f9645ebe0e
|
data/CHANGELOG
CHANGED
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
| Firefox and Tor Browser bookmarks with their folders | 0.14.0 | 2026-09-09 |
|
|
27
27
|
| `Browser::Bookmarks#tree`, the bookmarks as a tree, folders and all | 0.17.0 | 2026-10-03 |
|
|
28
28
|
| `profile_path`, the directory a profile sits in | 0.17.0 | 2026-10-03 |
|
|
29
|
+
| `Browser::Visit`, history as one record whatever the browser, the three epochs converted to a `Time` | 0.18.0 | 2026-10-05 |
|
|
30
|
+
| `Browser::History#visits`, the records, each carrying the browser's own columns besides | 0.18.0 | 2026-10-05 |
|
|
31
|
+
| Every meaningful history column carried, each browser's own bookkeeping left out | 0.19.0 | 2026-10-06 |
|
|
32
|
+
| Safari's history titles, which its query had never asked for | 0.19.0 | 2026-10-06 |
|
|
29
33
|
|
|
30
34
|
|
|
31
35
|
## Capabilities, per browser, and when each arrived
|
|
@@ -41,6 +45,54 @@ The README's table, with each cell holding the version at which it became true.
|
|
|
41
45
|
| Safari | 0.6.1 | 0.4.0 | 0.10.0 | none | none |
|
|
42
46
|
| Tor Browser | 0.7.0 | 0.7.0 | 0.14.0 | 0.7.0 | 0.13.0 |
|
|
43
47
|
|
|
48
|
+
## 20261006
|
|
49
|
+
|
|
50
|
+
0.19.0: ~ the history queries: carry everything meaningful, the bookkeeping left out; + Safari's titles.
|
|
51
|
+
|
|
52
|
+
1. ~ Browser::Safari.history_sql: + history_visits.title, which Safari has held all along and the query had never asked for.
|
|
53
|
+
2. So Browser::Visit#title is no longer nil for Safari, and to_objects, to_csv, to_json and to_plist carry it.
|
|
54
|
+
3. 0.18.0 shipped the claim that Safari stores no title, in Browser::Visit's header and in README.md, and it was never so.
|
|
55
|
+
4. ~ the same: + load_successful, http_non_get, synthesized, redirect_source, redirect_destination, origin, visit_count and status_code.
|
|
56
|
+
5. ~ the same: history_visits.id in place of history_items.id, a row being a visit rather than an item.
|
|
57
|
+
6. ~ the same: the join driven from history_visits, ON rather than a WHERE, so that a visit whose item is gone arrives with no url in place of vanishing.
|
|
58
|
+
7. ~ Browser::FirefoxBased.history_sql: + from_visit, visit_type, session, source, visit_count, hidden, typed, last_visit_date, guid, description, preview_image_url and site_name, four columns of twenty-seven becoming sixteen.
|
|
59
|
+
8. - from both: the internal keys, the index helpers, the opaque blobs, the ranking scores and their recalculation flags, which are each browser's own bookkeeping and tell a consumer nothing.
|
|
60
|
+
9. Browser::ChromiumBased.history_sql is unchanged, SELECT * over urls carrying all seven of its columns, every one of them meaningful.
|
|
61
|
+
10. to_objects is untouched throughout, so the renderers carry the same three fields and the detail rides on attributes.
|
|
62
|
+
11. ~ Browser::Visit: the header, which had said Chromium's visit_count, typed_count and hidden have no counterpart in the others; moz_places holds visit_count, hidden and typed, and the query had not asked.
|
|
63
|
+
12. ~ Rakefile: + status_code to the Safari fixture's history_items, which the real table has and the fixture lacked.
|
|
64
|
+
13. ~ the same: the Firefox fixture's place carrying a visit_count, typed, last_visit_date, guid, description and site_name, and its visit a session and a source.
|
|
65
|
+
14. ~ test/fixtures/Safari_history.sqlite, FirefoxBased_places.sqlite rebuilt.
|
|
66
|
+
15. ~ test/Browser/Safari_test.rb: the history expected with its titles; + the carried detail and the bookkeeping left out.
|
|
67
|
+
16. ~ test/Browser/Firefox_test.rb, TorBrowser_test.rb: the widened sql; + the same.
|
|
68
|
+
17. ~ test/Browser/Visit_test.rb: a nil title is a browser which gave none, not Safari.
|
|
69
|
+
18. ~ README.md: what attributes carries, in place of the claim about Safari's titles.
|
|
70
|
+
19. ~ Browser::VERSION: /0.18.0/0.19.0/
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## 20261005
|
|
74
|
+
|
|
75
|
+
0.18.0: + Browser::Visit, history as one representation whatever the browser.
|
|
76
|
+
|
|
77
|
+
1. + Browser::Visit: url, title and visited_at, the three every browser holds, with the browser's own row kept as attributes.
|
|
78
|
+
2. + Browser::History#visits: the history as those records.
|
|
79
|
+
3. ~ Browser::History#to_objects: the three fields, in place of each browser's own columns, which it had zipped from the query.
|
|
80
|
+
4. The renderers follow to_objects, so to_csv, to_json and to_plist now carry one shape whatever the browser, which is what converting one browser's history to another's wants; a consumer reading the old columns reads them from attributes now.
|
|
81
|
+
5. ~ Browser::History: - column_names taken from the query; + the three.
|
|
82
|
+
6. + Browser::ChromiumBased::HISTORY_EPOCH, FirefoxBased's and Safari's: 1601, 1970 and 2001.
|
|
83
|
+
7. + .visited_at to each of the three: the epoch plus the stored value, through Rational where that value is microseconds, no float being exact over it.
|
|
84
|
+
8. Safari's title is nil throughout, Safari storing none with its history.
|
|
85
|
+
9. A Chromium row stays a url and the last visit to it where Firefox's and Safari's are single visits; TODO holds the visits table which would even it.
|
|
86
|
+
10. + lib/Browser/Visit.rb, + test/Browser/Visit_test.rb
|
|
87
|
+
11. ~ test/Browser/Brave_test.rb, Chrome_test.rb, Chromium_test.rb, Firefox_test.rb, Safari_test.rb, TorBrowser_test.rb: the history expected as the three fields.
|
|
88
|
+
12. ~ the same: to_objects compared, where to_json had been, as the bookmarks are.
|
|
89
|
+
13. + test/Browser/Chromium_test.rb, Firefox_test.rb, Safari_test.rb: #visits, one per family, for the epoch and the surplus.
|
|
90
|
+
14. ~ README.md: + visits and the three epochs; + a Chromium row being a url rather than a visit; ~ the description, bookmarks and history both one representation now.
|
|
91
|
+
15. ~ ROADMAP.md: the representation theme, its history half answered.
|
|
92
|
+
16. ~ TODO: - the history representation, done; + Chromium's visits table.
|
|
93
|
+
17. ~ Browser::VERSION: /0.17.0/0.18.0/
|
|
94
|
+
|
|
95
|
+
|
|
44
96
|
## 20261003
|
|
45
97
|
|
|
46
98
|
0.17.0: + Browser::Bookmarks#tree, the bookmark tree; + Browser::Base#profile_path, the profile directory.
|
data/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Read the bookmarks and history of the web browsers on a machine — Brave, Chrome,
|
|
6
6
|
Chromium, Firefox, Safari and Tor Browser — and render them to CSV, JSON or a
|
|
7
|
-
property list. Bookmarks come through as one common representation
|
|
8
|
-
|
|
7
|
+
property list. Bookmarks and history each come through as one common representation
|
|
8
|
+
whatever the browser.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -42,7 +42,8 @@ chrome.bookmarks.to_objects # => [{title:, url:, folder:}, ...]
|
|
|
42
42
|
chrome.bookmarks.tree # => Browser::Bookmark, the folders and all
|
|
43
43
|
chrome.bookmarks.to_csv # title,url,folder rows
|
|
44
44
|
chrome.bookmarks.to_json
|
|
45
|
-
chrome.history.to_objects
|
|
45
|
+
chrome.history.to_objects # => [{url:, title:, visited_at:}, ...]
|
|
46
|
+
chrome.history.visits # => Browser::Visit, the browser's own columns too
|
|
46
47
|
chrome.profile_path # => the directory the profile sits in
|
|
47
48
|
```
|
|
48
49
|
|
|
@@ -74,6 +75,15 @@ a titleless root whose children are the browser's own roots, each folder holding
|
|
|
74
75
|
children. The renderers flatten that to leaves and drop the folders, so the tree is
|
|
75
76
|
where a folder, or `Bookmark#name`, is to be had.
|
|
76
77
|
|
|
78
|
+
`history.visits` is the history as `Browser::Visit`: a `url`, a `title` and
|
|
79
|
+
`visited_at`, which is a `Time` in UTC, with the browser's own row kept on
|
|
80
|
+
`attributes`. The three browsers count from three epochs — Chromium in microseconds
|
|
81
|
+
from 1601, Firefox in microseconds from 1970, Safari in seconds from 2001 — and all
|
|
82
|
+
three arrive converted. `attributes` carries everything else the browser holds which
|
|
83
|
+
a consumer could want, leaving out its internal keys, index helpers and ranking
|
|
84
|
+
scores: Firefox's `guid`, `description` and `visit_type`, Safari's `load_successful`
|
|
85
|
+
and `status_code`, the Chromium family's `typed_count`.
|
|
86
|
+
|
|
77
87
|
`profile_path` is the directory the profile sits in, which a Selenium front end wants
|
|
78
88
|
in place of a throwaway one. Safari, having no profiles, answers `nil`.
|
|
79
89
|
|
|
@@ -92,6 +102,11 @@ in place of a throwaway one. Safari, having no profiles, answers `nil`.
|
|
|
92
102
|
|
|
93
103
|
- **macOS only, for now.** Every location is a macOS path; Linux and Windows are on
|
|
94
104
|
the Todo.
|
|
105
|
+
- **A Chromium row is a URL, not a visit.** Chromium's history table holds one row per
|
|
106
|
+
URL, with a visit count and the time it was last visited, where Firefox and Safari
|
|
107
|
+
hold one row per visit. So a page visited three times is one record for Chrome,
|
|
108
|
+
Chromium and Brave and three for the others, and their `visited_at` is the last
|
|
109
|
+
visit rather than a visit. `attributes` carries `visit_count` for the family.
|
|
95
110
|
- **A running browser locks its database.** History, and Firefox's bookmarks, are
|
|
96
111
|
read from SQLite, which the browser locks while it is open — so reading a browser
|
|
97
112
|
you are using raises `Browser::Unreadable`. Ask `readable?` first, or quit it.
|
data/Rakefile
CHANGED
|
@@ -118,7 +118,18 @@ namespace :fixtures do
|
|
|
118
118
|
)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
# Place 5 is the one with history, so it carries what a visit holds besides the
|
|
122
|
+
# url and the title, which Browser::Visit keeps as attributes.
|
|
123
|
+
db.execute(
|
|
124
|
+
'UPDATE moz_places SET visit_count = ?, typed = ?, last_visit_date = ?, guid = ?, description = ?, site_name = ? WHERE id = ?',
|
|
125
|
+
[1, 1, added + 152741667, 'Ab1cD2eF3gH4', 'Recommended extensions for Firefox', 'addons.mozilla.org', 5]
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# source 0 is a local visit, 1 a synced one; visit_type 1 is a followed link.
|
|
129
|
+
db.execute(
|
|
130
|
+
'INSERT INTO moz_historyvisits (id, place_id, visit_date, visit_type, session, source) VALUES (?, ?, ?, ?, ?, ?)',
|
|
131
|
+
[1, 5, added + 152741667, 1, 1, 0]
|
|
132
|
+
)
|
|
122
133
|
db.close
|
|
123
134
|
puts "Wrote #{path} (#{File.size(path)} bytes)."
|
|
124
135
|
end
|
|
@@ -141,7 +152,8 @@ namespace :fixtures do
|
|
|
141
152
|
weekly_visit_counts BLOB NULL,
|
|
142
153
|
autocomplete_triggers BLOB NULL,
|
|
143
154
|
should_recompute_derived_visit_counts INTEGER NOT NULL,
|
|
144
|
-
visit_count_score INTEGER NOT NULL
|
|
155
|
+
visit_count_score INTEGER NOT NULL,
|
|
156
|
+
status_code INTEGER NOT NULL DEFAULT 0
|
|
145
157
|
);
|
|
146
158
|
CREATE TABLE history_visits (
|
|
147
159
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -161,12 +173,12 @@ namespace :fixtures do
|
|
|
161
173
|
CREATE INDEX history_visits_history_item_index ON history_visits (history_item);
|
|
162
174
|
SQL
|
|
163
175
|
[
|
|
164
|
-
[1, 'https://www.apple.com/', 'apple', 3, 1],
|
|
165
|
-
[2, 'https://support.apple.com/', 'support.apple', 1, 0],
|
|
166
|
-
].each do |id, url, domain, visit_count, score|
|
|
176
|
+
[1, 'https://www.apple.com/', 'apple', 3, 1, 200],
|
|
177
|
+
[2, 'https://support.apple.com/', 'support.apple', 1, 0, 200],
|
|
178
|
+
].each do |id, url, domain, visit_count, score, status_code|
|
|
167
179
|
db.execute(
|
|
168
|
-
'INSERT INTO history_items (id, url, domain_expansion, visit_count, daily_visit_counts, should_recompute_derived_visit_counts, visit_count_score) VALUES (?, ?, ?, ?, ?, 0, ?)',
|
|
169
|
-
[id, url, domain, visit_count, SQLite3::Blob.new(''), score]
|
|
180
|
+
'INSERT INTO history_items (id, url, domain_expansion, visit_count, daily_visit_counts, should_recompute_derived_visit_counts, visit_count_score, status_code) VALUES (?, ?, ?, ?, ?, 0, ?, ?)',
|
|
181
|
+
[id, url, domain, visit_count, SQLite3::Blob.new(''), score, status_code]
|
|
170
182
|
)
|
|
171
183
|
end
|
|
172
184
|
# visit_time is seconds since 2001-01-01, which is Core Data's epoch.
|
|
@@ -6,6 +6,7 @@ require_relative './Base'
|
|
|
6
6
|
class Browser
|
|
7
7
|
class ChromiumBased < Base
|
|
8
8
|
DEFAULT_PROFILE_NAME = "Default"
|
|
9
|
+
HISTORY_EPOCH = Time.utc(1601) # Chromium counts microseconds from here.
|
|
9
10
|
|
|
10
11
|
class << self
|
|
11
12
|
def bookmarks_location(profile_name: nil)
|
|
@@ -43,6 +44,10 @@ class Browser
|
|
|
43
44
|
def history_sql
|
|
44
45
|
'SELECT * FROM urls ORDER BY last_visit_time DESC;'
|
|
45
46
|
end
|
|
47
|
+
|
|
48
|
+
def visited_at(row)
|
|
49
|
+
HISTORY_EPOCH + Rational(row['last_visit_time'], 1_000_000)
|
|
50
|
+
end
|
|
46
51
|
end
|
|
47
52
|
end
|
|
48
53
|
end
|
data/lib/Browser/FirefoxBased.rb
CHANGED
|
@@ -5,6 +5,8 @@ require_relative './Base'
|
|
|
5
5
|
|
|
6
6
|
class Browser
|
|
7
7
|
class FirefoxBased < Base
|
|
8
|
+
HISTORY_EPOCH = Time.utc(1970) # Firefox counts microseconds from here.
|
|
9
|
+
|
|
8
10
|
class << self
|
|
9
11
|
def bookmarks_location(profile_name: nil)
|
|
10
12
|
profile_name ||= default_profile_name
|
|
@@ -78,8 +80,15 @@ class Browser
|
|
|
78
80
|
'SELECT moz_bookmarks.id, moz_bookmarks.parent, moz_bookmarks.position, moz_bookmarks.type, moz_bookmarks.title, moz_bookmarks.guid, moz_places.url FROM moz_bookmarks LEFT JOIN moz_places ON moz_bookmarks.fk = moz_places.id ORDER BY moz_bookmarks.parent, moz_bookmarks.position;'
|
|
79
81
|
end
|
|
80
82
|
|
|
83
|
+
# Everything either table holds which a consumer could want, which is all of
|
|
84
|
+
# them but the internal keys, rev_host and url_hash, and the frecency scores
|
|
85
|
+
# and their recalculation flags, all of which are Firefox's own bookkeeping.
|
|
81
86
|
def history_sql
|
|
82
|
-
'SELECT moz_historyvisits.id, moz_places.url, moz_places.title, moz_historyvisits.visit_date FROM moz_historyvisits LEFT JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'
|
|
87
|
+
'SELECT moz_historyvisits.id, moz_places.url, moz_places.title, moz_historyvisits.visit_date, moz_historyvisits.from_visit, moz_historyvisits.visit_type, moz_historyvisits.session, moz_historyvisits.source, moz_places.visit_count, moz_places.hidden, moz_places.typed, moz_places.last_visit_date, moz_places.guid, moz_places.description, moz_places.preview_image_url, moz_places.site_name FROM moz_historyvisits LEFT JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def visited_at(row)
|
|
91
|
+
HISTORY_EPOCH + Rational(row['visit_date'], 1_000_000)
|
|
83
92
|
end
|
|
84
93
|
end
|
|
85
94
|
end
|
data/lib/Browser/History.rb
CHANGED
|
@@ -5,13 +5,21 @@ require 'sqlite3'
|
|
|
5
5
|
|
|
6
6
|
require_relative './Rendering'
|
|
7
7
|
require_relative './Unreadable'
|
|
8
|
+
require_relative './Visit'
|
|
8
9
|
|
|
9
10
|
class Browser
|
|
10
11
|
class History
|
|
11
12
|
include Rendering
|
|
12
13
|
|
|
14
|
+
# The history as the browser keeps it, each row a Browser::Visit, which carries
|
|
15
|
+
# the browser's own columns besides the three they share. to_objects keeps only
|
|
16
|
+
# those three, so the surplus is reachable nowhere else.
|
|
17
|
+
def visits
|
|
18
|
+
@visits ||= rows.collect{|row| visit(row)}
|
|
19
|
+
end
|
|
20
|
+
|
|
13
21
|
def to_objects
|
|
14
|
-
|
|
22
|
+
visits.collect(&:to_h)
|
|
15
23
|
end
|
|
16
24
|
|
|
17
25
|
private
|
|
@@ -30,12 +38,22 @@ class Browser
|
|
|
30
38
|
raise Browser::Unreadable, "#{@browser_instance.history_location} is not readable: #{e.message}"
|
|
31
39
|
end
|
|
32
40
|
|
|
33
|
-
def
|
|
34
|
-
results
|
|
41
|
+
def rows
|
|
42
|
+
names, *values = results
|
|
43
|
+
values.collect{|value| names.zip(value).to_h}
|
|
35
44
|
end
|
|
36
45
|
|
|
37
|
-
def
|
|
38
|
-
|
|
46
|
+
def visit(row)
|
|
47
|
+
Browser::Visit.new(
|
|
48
|
+
url: row['url'],
|
|
49
|
+
title: row['title'],
|
|
50
|
+
visited_at: @browser_instance.class.send(:visited_at, row),
|
|
51
|
+
attributes: row,
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def column_names
|
|
56
|
+
%i{url title visited_at}
|
|
39
57
|
end
|
|
40
58
|
end
|
|
41
59
|
end
|
data/lib/Browser/Safari.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative './Base'
|
|
|
6
6
|
class Browser
|
|
7
7
|
class Safari < Base
|
|
8
8
|
DEFAULT_PROFILE_NAME = nil # Safari doesn't have profiles.
|
|
9
|
+
HISTORY_EPOCH = Time.utc(2001) # Safari counts seconds from here.
|
|
9
10
|
|
|
10
11
|
class << self
|
|
11
12
|
def bookmarks_location(profile_name: nil)
|
|
@@ -40,8 +41,16 @@ class Browser
|
|
|
40
41
|
nil
|
|
41
42
|
end
|
|
42
43
|
|
|
44
|
+
# Everything either table holds which a consumer could want, which leaves out
|
|
45
|
+
# the internal keys, domain_expansion, the visit count blobs and their
|
|
46
|
+
# recomputation flag, the two ranking scores, and generation and attributes,
|
|
47
|
+
# all of which are Safari's own bookkeeping.
|
|
43
48
|
def history_sql
|
|
44
|
-
'SELECT
|
|
49
|
+
'SELECT history_visits.id, history_items.url, history_visits.title, history_visits.visit_time, history_visits.load_successful, history_visits.http_non_get, history_visits.synthesized, history_visits.redirect_source, history_visits.redirect_destination, history_visits.origin, history_items.visit_count, history_items.status_code FROM history_visits LEFT JOIN history_items ON history_visits.history_item = history_items.id ORDER BY history_visits.visit_time DESC;'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def visited_at(row)
|
|
53
|
+
HISTORY_EPOCH + row['visit_time']
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
56
|
end
|
data/lib/Browser/VERSION.rb
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Browser/Visit.rb
|
|
2
|
+
# Browser::Visit
|
|
3
|
+
|
|
4
|
+
# It knows nothing of how a browser stores history, only the shape they share once
|
|
5
|
+
# read: a url, a title and a time. For Firefox and Safari a row is one visit; for
|
|
6
|
+
# the Chromium family it is a url and the last visit to it, so a page visited three
|
|
7
|
+
# times is one Visit there and three elsewhere. The browser's own row stays as
|
|
8
|
+
# attributes, under the names that browser gave it: all three keep a visit count,
|
|
9
|
+
# Firefox alone a guid and a description, and Safari alone whether the page loaded
|
|
10
|
+
# and with what status.
|
|
11
|
+
|
|
12
|
+
class Browser
|
|
13
|
+
class Visit
|
|
14
|
+
attr_accessor :url, :title, :visited_at, :attributes
|
|
15
|
+
|
|
16
|
+
def to_h
|
|
17
|
+
{url: @url, title: @title, visited_at: @visited_at}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def initialize(url: nil, title: nil, visited_at: nil, attributes: {})
|
|
23
|
+
@url = url
|
|
24
|
+
@title = title
|
|
25
|
+
@visited_at = visited_at
|
|
26
|
+
@attributes = attributes
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/test/Browser/Brave_test.rb
CHANGED
|
@@ -72,8 +72,8 @@ describe Browser::Brave do
|
|
|
72
72
|
let(:default_profile_name){'Default'}
|
|
73
73
|
let(:expected_history) do
|
|
74
74
|
[
|
|
75
|
-
{
|
|
76
|
-
{
|
|
75
|
+
{url: 'https://www.chromium.org/chromium-projects/', title: 'Home', visited_at: Time.utc(2025, 9, 25)},
|
|
76
|
+
{url: 'chrome://welcome/', title: 'Welcome', visited_at: Time.utc(2025, 9, 24, 23, 43, 20)},
|
|
77
77
|
]
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -129,7 +129,7 @@ describe Browser::Brave do
|
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
it "returns the history" do
|
|
132
|
-
expect(subject.history.
|
|
132
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
|
data/test/Browser/Chrome_test.rb
CHANGED
|
@@ -72,8 +72,8 @@ describe Browser::Chrome do
|
|
|
72
72
|
let(:default_profile_name){'Default'}
|
|
73
73
|
let(:expected_history) do
|
|
74
74
|
[
|
|
75
|
-
{
|
|
76
|
-
{
|
|
75
|
+
{url: 'https://www.chromium.org/chromium-projects/', title: 'Home', visited_at: Time.utc(2025, 9, 25)},
|
|
76
|
+
{url: 'chrome://welcome/', title: 'Welcome', visited_at: Time.utc(2025, 9, 24, 23, 43, 20)},
|
|
77
77
|
]
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -129,7 +129,7 @@ describe Browser::Chrome do
|
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
it "returns the history" do
|
|
132
|
-
expect(subject.history.
|
|
132
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
|
|
@@ -76,8 +76,8 @@ describe Browser::Chromium do
|
|
|
76
76
|
let(:default_profile_name){'Default'}
|
|
77
77
|
let(:expected_history) do
|
|
78
78
|
[
|
|
79
|
-
{
|
|
80
|
-
{
|
|
79
|
+
{url: 'https://www.chromium.org/chromium-projects/', title: 'Home', visited_at: Time.utc(2025, 9, 25)},
|
|
80
|
+
{url: 'chrome://welcome/', title: 'Welcome', visited_at: Time.utc(2025, 9, 24, 23, 43, 20)},
|
|
81
81
|
]
|
|
82
82
|
end
|
|
83
83
|
|
|
@@ -143,7 +143,15 @@ describe Browser::Chromium do
|
|
|
143
143
|
end
|
|
144
144
|
|
|
145
145
|
it "returns the history" do
|
|
146
|
-
expect(subject.history.
|
|
146
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "returns the visits, which carry the browser's own columns besides" do
|
|
150
|
+
visit = subject.history.visits.first
|
|
151
|
+
expect(visit).to be_a(Browser::Visit)
|
|
152
|
+
expect(visit.visited_at).to eq(Time.utc(2025, 9, 25))
|
|
153
|
+
expect(visit.attributes['visit_count']).to eq(3)
|
|
154
|
+
expect(visit.attributes['last_visit_time']).to eq(13403232000000000)
|
|
147
155
|
end
|
|
148
156
|
end
|
|
149
157
|
|
|
@@ -18,7 +18,7 @@ require 'browser'
|
|
|
18
18
|
describe Browser::Firefox do
|
|
19
19
|
let(:places_fixtures_location){File.expand_path("#{__FILE__}/../../fixtures/FirefoxBased_places.sqlite")}
|
|
20
20
|
let(:expected_bookmarks_sql){'SELECT moz_bookmarks.id, moz_bookmarks.parent, moz_bookmarks.position, moz_bookmarks.type, moz_bookmarks.title, moz_bookmarks.guid, moz_places.url FROM moz_bookmarks LEFT JOIN moz_places ON moz_bookmarks.fk = moz_places.id ORDER BY moz_bookmarks.parent, moz_bookmarks.position;'}
|
|
21
|
-
let(:expected_history_sql){'SELECT moz_historyvisits.id, moz_places.url, moz_places.title, moz_historyvisits.visit_date FROM moz_historyvisits LEFT JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'}
|
|
21
|
+
let(:expected_history_sql){'SELECT moz_historyvisits.id, moz_places.url, moz_places.title, moz_historyvisits.visit_date, moz_historyvisits.from_visit, moz_historyvisits.visit_type, moz_historyvisits.session, moz_historyvisits.source, moz_places.visit_count, moz_places.hidden, moz_places.typed, moz_places.last_visit_date, moz_places.guid, moz_places.description, moz_places.preview_image_url, moz_places.site_name FROM moz_historyvisits LEFT JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'}
|
|
22
22
|
|
|
23
23
|
describe '.default_profile_name' do
|
|
24
24
|
let(:profiles_ini) do
|
|
@@ -116,7 +116,7 @@ describe Browser::Firefox do
|
|
|
116
116
|
let(:browser_name){'Firefox'}
|
|
117
117
|
let(:expected_history) do
|
|
118
118
|
[
|
|
119
|
-
{
|
|
119
|
+
{url: 'https://addons.mozilla.org/en-US/firefox/', title: 'Extension Starter Pack', visited_at: Time.utc(2026, 8, 23, 1, 39, 12) + Rational(741_667, 1_000_000)},
|
|
120
120
|
]
|
|
121
121
|
end
|
|
122
122
|
|
|
@@ -185,7 +185,25 @@ describe Browser::Firefox do
|
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
it "returns the history" do
|
|
188
|
-
expect(subject.history.
|
|
188
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "returns the visits, converting Firefox's microseconds from 1970" do
|
|
192
|
+
visit = subject.history.visits.first
|
|
193
|
+
expect(visit).to be_a(Browser::Visit)
|
|
194
|
+
expect(visit.visited_at).to eq(Time.utc(2026, 8, 23, 1, 39, 12) + Rational(741_667, 1_000_000))
|
|
195
|
+
expect(visit.attributes['visit_date']).to eq(1787449152741667)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it "carries everything meaningful either table holds, and none of the bookkeeping" do
|
|
199
|
+
attributes = subject.history.visits.first.attributes
|
|
200
|
+
expect(attributes['guid']).to eq('Ab1cD2eF3gH4')
|
|
201
|
+
expect(attributes['description']).to eq('Recommended extensions for Firefox')
|
|
202
|
+
expect(attributes['site_name']).to eq('addons.mozilla.org')
|
|
203
|
+
expect(attributes['visit_type']).to eq(1)
|
|
204
|
+
expect(attributes['source']).to eq(0)
|
|
205
|
+
expect(attributes['visit_count']).to eq(1)
|
|
206
|
+
expect(attributes.keys).to_not include('place_id', 'rev_host', 'url_hash', 'frecency')
|
|
189
207
|
end
|
|
190
208
|
end
|
|
191
209
|
|
data/test/Browser/Safari_test.rb
CHANGED
|
@@ -15,7 +15,7 @@ require 'browser'
|
|
|
15
15
|
describe Browser::Safari do
|
|
16
16
|
let(:bookmarks_fixtures_location){File.expand_path("#{__FILE__}/../../fixtures/Safari_bookmarks.plist")}
|
|
17
17
|
let(:history_fixtures_location){File.expand_path("#{__FILE__}/../../fixtures/Safari_history.sqlite")}
|
|
18
|
-
let(:expected_history_sql){'SELECT
|
|
18
|
+
let(:expected_history_sql){'SELECT history_visits.id, history_items.url, history_visits.title, history_visits.visit_time, history_visits.load_successful, history_visits.http_non_get, history_visits.synthesized, history_visits.redirect_source, history_visits.redirect_destination, history_visits.origin, history_items.visit_count, history_items.status_code FROM history_visits LEFT JOIN history_items ON history_visits.history_item = history_items.id ORDER BY history_visits.visit_time DESC;'}
|
|
19
19
|
|
|
20
20
|
describe 'DEFAULT_PROFILE_NAME' do
|
|
21
21
|
it "has no default profile name" do
|
|
@@ -67,8 +67,8 @@ describe Browser::Safari do
|
|
|
67
67
|
let(:browser_name){'Safari'}
|
|
68
68
|
let(:expected_history) do
|
|
69
69
|
[
|
|
70
|
-
{
|
|
71
|
-
{
|
|
70
|
+
{url: 'https://www.apple.com/', title: 'Apple', visited_at: Time.utc(2025, 9, 25)},
|
|
71
|
+
{url: 'https://support.apple.com/', title: 'Apple Support', visited_at: Time.utc(2025, 9, 24, 23, 40)},
|
|
72
72
|
]
|
|
73
73
|
end
|
|
74
74
|
|
|
@@ -141,7 +141,24 @@ describe Browser::Safari do
|
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
it "returns the history" do
|
|
144
|
-
expect(subject.history.
|
|
144
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "returns the visits, with the title history_visits holds" do
|
|
148
|
+
visit = subject.history.visits.first
|
|
149
|
+
expect(visit).to be_a(Browser::Visit)
|
|
150
|
+
expect(visit.title).to eq('Apple')
|
|
151
|
+
expect(visit.visited_at).to eq(Time.utc(2025, 9, 25))
|
|
152
|
+
expect(visit.attributes['visit_time']).to eq(780451200.0)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "carries everything meaningful either table holds, and none of the bookkeeping" do
|
|
156
|
+
attributes = subject.history.visits.first.attributes
|
|
157
|
+
expect(attributes['load_successful']).to eq(1)
|
|
158
|
+
expect(attributes['status_code']).to eq(200)
|
|
159
|
+
expect(attributes['visit_count']).to eq(3)
|
|
160
|
+
expect(attributes['origin']).to eq(0)
|
|
161
|
+
expect(attributes.keys).to_not include('history_item', 'domain_expansion', 'daily_visit_counts', 'visit_count_score', 'score', 'generation', 'attributes')
|
|
145
162
|
end
|
|
146
163
|
end
|
|
147
164
|
|
|
@@ -15,7 +15,7 @@ require 'browser'
|
|
|
15
15
|
describe Browser::TorBrowser do
|
|
16
16
|
let(:places_fixtures_location){File.expand_path("#{__FILE__}/../../fixtures/FirefoxBased_places.sqlite")}
|
|
17
17
|
let(:expected_bookmarks_sql){'SELECT moz_bookmarks.id, moz_bookmarks.parent, moz_bookmarks.position, moz_bookmarks.type, moz_bookmarks.title, moz_bookmarks.guid, moz_places.url FROM moz_bookmarks LEFT JOIN moz_places ON moz_bookmarks.fk = moz_places.id ORDER BY moz_bookmarks.parent, moz_bookmarks.position;'}
|
|
18
|
-
let(:expected_history_sql){'SELECT moz_historyvisits.id, moz_places.url, moz_places.title, moz_historyvisits.visit_date FROM moz_historyvisits LEFT JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'}
|
|
18
|
+
let(:expected_history_sql){'SELECT moz_historyvisits.id, moz_places.url, moz_places.title, moz_historyvisits.visit_date, moz_historyvisits.from_visit, moz_historyvisits.visit_type, moz_historyvisits.session, moz_historyvisits.source, moz_places.visit_count, moz_places.hidden, moz_places.typed, moz_places.last_visit_date, moz_places.guid, moz_places.description, moz_places.preview_image_url, moz_places.site_name FROM moz_historyvisits LEFT JOIN moz_places ON moz_historyvisits.place_id = moz_places.id ORDER BY moz_historyvisits.visit_date DESC;'}
|
|
19
19
|
|
|
20
20
|
describe '.default_profile_name' do
|
|
21
21
|
let(:profiles_ini){"[Profile0]\nName=default\nIsRelative=1\nPath=abcd1234.default\nDefault=1\n\n[General]\nStartWithLastProfile=1\nVersion=2\n"}
|
|
@@ -73,7 +73,7 @@ describe Browser::TorBrowser do
|
|
|
73
73
|
let(:browser_name){'TorBrowser'}
|
|
74
74
|
let(:expected_history) do
|
|
75
75
|
[
|
|
76
|
-
{
|
|
76
|
+
{url: 'https://addons.mozilla.org/en-US/firefox/', title: 'Extension Starter Pack', visited_at: Time.utc(2026, 8, 23, 1, 39, 12) + Rational(741_667, 1_000_000)},
|
|
77
77
|
]
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -133,7 +133,7 @@ describe Browser::TorBrowser do
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it "returns the history" do
|
|
136
|
-
expect(subject.history.
|
|
136
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Visit_test.rb
|
|
2
|
+
|
|
3
|
+
gem 'minitest'
|
|
4
|
+
gem 'minitest-spec-context'
|
|
5
|
+
|
|
6
|
+
require 'minitest/autorun'
|
|
7
|
+
require 'minitest-spec-context'
|
|
8
|
+
require 'rspec/expectations/minitest_integration'
|
|
9
|
+
|
|
10
|
+
lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
|
|
11
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
12
|
+
|
|
13
|
+
require 'browser'
|
|
14
|
+
|
|
15
|
+
describe Browser::Visit do
|
|
16
|
+
let(:visited_at){Time.utc(2025, 9, 25)}
|
|
17
|
+
|
|
18
|
+
describe "#to_h" do
|
|
19
|
+
it "keeps the three fields every browser holds, and nothing else" do
|
|
20
|
+
visit = Browser::Visit.new(
|
|
21
|
+
url: 'https://example.com/',
|
|
22
|
+
title: 'Home',
|
|
23
|
+
visited_at: visited_at,
|
|
24
|
+
attributes: {'visit_count' => 3},
|
|
25
|
+
)
|
|
26
|
+
expect(visit.to_h).to eq({url: 'https://example.com/', title: 'Home', visited_at: visited_at})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "carries a nil title where the browser gave none" do
|
|
30
|
+
expect(Browser::Visit.new(url: 'https://example.com/', visited_at: visited_at).to_h[:title]).to be_nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#attributes" do
|
|
35
|
+
it "holds the browser's own row, which to_h drops" do
|
|
36
|
+
row = {'id' => 1, 'url' => 'https://example.com/', 'visit_count' => 3, 'hidden' => 0}
|
|
37
|
+
expect(Browser::Visit.new(url: 'https://example.com/', attributes: row).attributes).to eq(row)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "is empty when the browser gave none" do
|
|
41
|
+
expect(Browser::Visit.new(url: 'https://example.com/').attributes).to eq({})
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
Binary file
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: browser.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.19.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -149,6 +149,7 @@ files:
|
|
|
149
149
|
- lib/Browser/TorBrowser.rb
|
|
150
150
|
- lib/Browser/Unreadable.rb
|
|
151
151
|
- lib/Browser/VERSION.rb
|
|
152
|
+
- lib/Browser/Visit.rb
|
|
152
153
|
- lib/browser-classes.rb
|
|
153
154
|
- lib/browser.rb
|
|
154
155
|
- test/Browser/Bookmark_test.rb
|
|
@@ -159,6 +160,7 @@ files:
|
|
|
159
160
|
- test/Browser/Rendering_test.rb
|
|
160
161
|
- test/Browser/Safari_test.rb
|
|
161
162
|
- test/Browser/TorBrowser_test.rb
|
|
163
|
+
- test/Browser/Visit_test.rb
|
|
162
164
|
- test/browser_test.rb
|
|
163
165
|
- test/fixtures/Brave_bookmarks.json
|
|
164
166
|
- test/fixtures/ChromiumBased_history.sqlite
|