browser.rb 0.17.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6736107069b9106898aa3d0cd4eff7cc871accd26202c2216852dae6f1de78a4
4
- data.tar.gz: 27905d0383d166591313067fea7240b69198e66e21ec43517ea29170749fe55b
3
+ metadata.gz: 56f139b18dfff55d6bc1cb220969ae862e8fd8f0faba7f4c9c1d328fcdb87e0f
4
+ data.tar.gz: 741fbfa0b248ffe280a7677aa83a49d835317471c7267a8cc90a0f9bb4bc68bb
5
5
  SHA512:
6
- metadata.gz: e4a5cd271f4d2894e8967a806e16ecd8e592635ab09dc7b012de8bd9d056f909d06fe451d8fd4d404e3b2cc0d5c7ff63dcb5abe29c5be3330d26b18ab2b050f0
7
- data.tar.gz: ef6ef839d154af43f6d8bbabdfa7c286fa6f51b6ccbed710c4bb3502a179ebf33f944f3ac3e94f3fd4b2ea2848b7b8b159ab0e399aa009646dadc9fdf14aa5c5
6
+ metadata.gz: 770fc41a0c5a3092bbe120a72e8c38ccf8d75b42fe85237bd0e09dc452a0e7e3bc0dc57648ce5a9cfbca06983298c1e45cf31a1cd74c39b1bb6ad707c9c47ac2
7
+ data.tar.gz: b7c30b4d4575a9a707dd75b0f2c3b057b53f37f4a17e07ddfc1628aa53b810f9cc0eb487d82dc1cd7ef7fb3dafaa9a650f5079cfcc87d5d1ff6f180a20b5dd31
data/CHANGELOG CHANGED
@@ -26,6 +26,8 @@
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 |
29
31
 
30
32
 
31
33
  ## Capabilities, per browser, and when each arrived
@@ -41,6 +43,29 @@ The README's table, with each cell holding the version at which it became true.
41
43
  | Safari | 0.6.1 | 0.4.0 | 0.10.0 | none | none |
42
44
  | Tor Browser | 0.7.0 | 0.7.0 | 0.14.0 | 0.7.0 | 0.13.0 |
43
45
 
46
+ ## 20261005
47
+
48
+ 0.18.0: + Browser::Visit, history as one representation whatever the browser.
49
+
50
+ 1. + Browser::Visit: url, title and visited_at, the three every browser holds, with the browser's own row kept as attributes.
51
+ 2. + Browser::History#visits: the history as those records.
52
+ 3. ~ Browser::History#to_objects: the three fields, in place of each browser's own columns, which it had zipped from the query.
53
+ 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.
54
+ 5. ~ Browser::History: - column_names taken from the query; + the three.
55
+ 6. + Browser::ChromiumBased::HISTORY_EPOCH, FirefoxBased's and Safari's: 1601, 1970 and 2001.
56
+ 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.
57
+ 8. Safari's title is nil throughout, Safari storing none with its history.
58
+ 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.
59
+ 10. + lib/Browser/Visit.rb, + test/Browser/Visit_test.rb
60
+ 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.
61
+ 12. ~ the same: to_objects compared, where to_json had been, as the bookmarks are.
62
+ 13. + test/Browser/Chromium_test.rb, Firefox_test.rb, Safari_test.rb: #visits, one per family, for the epoch and the surplus.
63
+ 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.
64
+ 15. ~ ROADMAP.md: the representation theme, its history half answered.
65
+ 16. ~ TODO: - the history representation, done; + Chromium's visits table.
66
+ 17. ~ Browser::VERSION: /0.17.0/0.18.0/
67
+
68
+
44
69
  ## 20261003
45
70
 
46
71
  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 whatever the
8
- browser; history as each browser stores it.
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,13 @@ 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. Safari stores no title with its history, so that field is nil
83
+ there.
84
+
77
85
  `profile_path` is the directory the profile sits in, which a Selenium front end wants
78
86
  in place of a throwaway one. Safari, having no profiles, answers `nil`.
79
87
 
@@ -92,6 +100,11 @@ in place of a throwaway one. Safari, having no profiles, answers `nil`.
92
100
 
93
101
  - **macOS only, for now.** Every location is a macOS path; Linux and Windows are on
94
102
  the Todo.
103
+ - **A Chromium row is a URL, not a visit.** Chromium's history table holds one row per
104
+ URL, with a visit count and the time it was last visited, where Firefox and Safari
105
+ hold one row per visit. So a page visited three times is one record for Chrome,
106
+ Chromium and Brave and three for the others, and their `visited_at` is the last
107
+ visit rather than a visit. `attributes` carries `visit_count` for the family.
95
108
  - **A running browser locks its database.** History, and Firefox's bookmarks, are
96
109
  read from SQLite, which the browser locks while it is open — so reading a browser
97
110
  you are using raises `Browser::Unreadable`. Ask `readable?` first, or quit it.
@@ -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
@@ -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
@@ -81,6 +83,10 @@ class Browser
81
83
  def history_sql
82
84
  '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;'
83
85
  end
86
+
87
+ def visited_at(row)
88
+ HISTORY_EPOCH + Rational(row['visit_date'], 1_000_000)
89
+ end
84
90
  end
85
91
  end
86
92
  end
@@ -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
- rows.collect{|row| column_names.zip(row).to_h}
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 column_names
34
- results.first
41
+ def rows
42
+ names, *values = results
43
+ values.collect{|value| names.zip(value).to_h}
35
44
  end
36
45
 
37
- def rows
38
- results.drop(1)
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
@@ -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)
@@ -43,6 +44,10 @@ class Browser
43
44
  def history_sql
44
45
  'SELECT history_items.id, history_items.url, history_visits.visit_time FROM history_items LEFT JOIN history_visits WHERE history_items.id = history_visits.history_item ORDER BY visit_time DESC;'
45
46
  end
47
+
48
+ def visited_at(row)
49
+ HISTORY_EPOCH + row['visit_time']
50
+ end
46
51
  end
47
52
  end
48
53
  end
@@ -2,5 +2,5 @@
2
2
  # Browser::VERSION
3
3
 
4
4
  class Browser
5
- VERSION = '0.17.0'
5
+ VERSION = '0.18.0'
6
6
  end
@@ -0,0 +1,28 @@
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, since Chromium's visit_count, typed_count and hidden have no
9
+ # counterpart in the others, and Safari stores no title at all.
10
+
11
+ class Browser
12
+ class Visit
13
+ attr_accessor :url, :title, :visited_at, :attributes
14
+
15
+ def to_h
16
+ {url: @url, title: @title, visited_at: @visited_at}
17
+ end
18
+
19
+ private
20
+
21
+ def initialize(url: nil, title: nil, visited_at: nil, attributes: {})
22
+ @url = url
23
+ @title = title
24
+ @visited_at = visited_at
25
+ @attributes = attributes
26
+ end
27
+ end
28
+ end
@@ -72,8 +72,8 @@ describe Browser::Brave do
72
72
  let(:default_profile_name){'Default'}
73
73
  let(:expected_history) do
74
74
  [
75
- {'id' => 1, 'url' => 'https://www.chromium.org/chromium-projects/', 'title' => 'Home', 'visit_count' => 3, 'typed_count' => 1, 'last_visit_time' => 13403232000000000, 'hidden' => 0},
76
- {'id' => 2, 'url' => 'chrome://welcome/', 'title' => 'Welcome', 'visit_count' => 1, 'typed_count' => 0, 'last_visit_time' => 13403231000000000, 'hidden' => 0},
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.to_json).to eq(expected_history.to_json)
132
+ expect(subject.history.to_objects).to eq(expected_history)
133
133
  end
134
134
  end
135
135
 
@@ -72,8 +72,8 @@ describe Browser::Chrome do
72
72
  let(:default_profile_name){'Default'}
73
73
  let(:expected_history) do
74
74
  [
75
- {'id' => 1, 'url' => 'https://www.chromium.org/chromium-projects/', 'title' => 'Home', 'visit_count' => 3, 'typed_count' => 1, 'last_visit_time' => 13403232000000000, 'hidden' => 0},
76
- {'id' => 2, 'url' => 'chrome://welcome/', 'title' => 'Welcome', 'visit_count' => 1, 'typed_count' => 0, 'last_visit_time' => 13403231000000000, 'hidden' => 0},
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.to_json).to eq(expected_history.to_json)
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
- {'id' => 1, 'url' => 'https://www.chromium.org/chromium-projects/', 'title' => 'Home', 'visit_count' => 3, 'typed_count' => 1, 'last_visit_time' => 13403232000000000, 'hidden' => 0},
80
- {'id' => 2, 'url' => 'chrome://welcome/', 'title' => 'Welcome', 'visit_count' => 1, 'typed_count' => 0, 'last_visit_time' => 13403231000000000, 'hidden' => 0},
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.to_json).to eq(expected_history.to_json)
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
 
@@ -116,7 +116,7 @@ describe Browser::Firefox do
116
116
  let(:browser_name){'Firefox'}
117
117
  let(:expected_history) do
118
118
  [
119
- {'id' => 1, 'url' => 'https://addons.mozilla.org/en-US/firefox/', 'title' => 'Extension Starter Pack', 'visit_date' => 1787449152741667},
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,14 @@ describe Browser::Firefox do
185
185
  end
186
186
 
187
187
  it "returns the history" do
188
- expect(subject.history.to_json).to eq(expected_history.to_json)
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)
189
196
  end
190
197
  end
191
198
 
@@ -67,8 +67,8 @@ describe Browser::Safari do
67
67
  let(:browser_name){'Safari'}
68
68
  let(:expected_history) do
69
69
  [
70
- {'id' => 1, 'url' => 'https://www.apple.com/', 'visit_time' => 780451200.0},
71
- {'id' => 2, 'url' => 'https://support.apple.com/', 'visit_time' => 780450000.0},
70
+ {url: 'https://www.apple.com/', title: nil, visited_at: Time.utc(2025, 9, 25)},
71
+ {url: 'https://support.apple.com/', title: nil, visited_at: Time.utc(2025, 9, 24, 23, 40)},
72
72
  ]
73
73
  end
74
74
 
@@ -141,7 +141,15 @@ describe Browser::Safari do
141
141
  end
142
142
 
143
143
  it "returns the history" do
144
- expect(subject.history.to_json).to eq(expected_history.to_json)
144
+ expect(subject.history.to_objects).to eq(expected_history)
145
+ end
146
+
147
+ it "returns the visits, with no title, Safari storing none" do
148
+ visit = subject.history.visits.first
149
+ expect(visit).to be_a(Browser::Visit)
150
+ expect(visit.title).to be_nil
151
+ expect(visit.visited_at).to eq(Time.utc(2025, 9, 25))
152
+ expect(visit.attributes['visit_time']).to eq(780451200.0)
145
153
  end
146
154
  end
147
155
 
@@ -73,7 +73,7 @@ describe Browser::TorBrowser do
73
73
  let(:browser_name){'TorBrowser'}
74
74
  let(:expected_history) do
75
75
  [
76
- {'id' => 1, 'url' => 'https://addons.mozilla.org/en-US/firefox/', 'title' => 'Extension Starter Pack', 'visit_date' => 1787449152741667},
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.to_json).to eq(expected_history.to_json)
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, which Safari stores none of" 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
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.17.0
4
+ version: 0.18.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