browser.rb 0.16.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 +4 -4
- data/CHANGELOG +51 -7
- data/README.md +26 -3
- data/browser.rb.gemspec +1 -1
- data/lib/Browser/Base.rb +15 -0
- data/lib/Browser/Bookmarks.rb +7 -0
- data/lib/Browser/ChromiumBased.rb +5 -0
- data/lib/Browser/FirefoxBased.rb +6 -0
- data/lib/Browser/History.rb +23 -5
- data/lib/Browser/Safari.rb +5 -0
- data/lib/Browser/VERSION.rb +1 -1
- data/lib/Browser/Visit.rb +28 -0
- data/test/Browser/Brave_test.rb +17 -3
- data/test/Browser/Chrome_test.rb +17 -3
- data/test/Browser/Chromium_test.rb +39 -3
- data/test/Browser/Firefox_test.rb +32 -2
- data/test/Browser/Safari_test.rb +28 -3
- data/test/Browser/TorBrowser_test.rb +16 -2
- data/test/Browser/Visit_test.rb +44 -0
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 56f139b18dfff55d6bc1cb220969ae862e8fd8f0faba7f4c9c1d328fcdb87e0f
|
|
4
|
+
data.tar.gz: 741fbfa0b248ffe280a7677aa83a49d835317471c7267a8cc90a0f9bb4bc68bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 770fc41a0c5a3092bbe120a72e8c38ccf8d75b42fe85237bd0e09dc452a0e7e3bc0dc57648ce5a9cfbca06983298c1e45cf31a1cd74c39b1bb6ad707c9c47ac2
|
|
7
|
+
data.tar.gz: b7c30b4d4575a9a707dd75b0f2c3b057b53f37f4a17e07ddfc1628aa53b810f9cc0eb487d82dc1cd7ef7fb3dafaa9a650f5079cfcc87d5d1ff6f180a20b5dd31
|
data/CHANGELOG
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
# browser/CHANGELOG
|
|
2
2
|
|
|
3
|
-
## How this history is kept
|
|
4
|
-
|
|
5
|
-
The revisions behind 0.0.0 to 0.6.0 are the record and are not rewritten; the entries
|
|
6
|
-
describing them are narration, and may be corrected toward that record at any time.
|
|
7
|
-
Once a version is published that licence ends: what is published is history someone
|
|
8
|
-
else may hold, and stays.
|
|
9
|
-
|
|
10
3
|
## Capabilities, and when each arrived
|
|
11
4
|
|
|
12
5
|
| capability | version | date |
|
|
@@ -31,6 +24,10 @@ else may hold, and stays.
|
|
|
31
24
|
| One set of renderers, shared by bookmarks and history | 0.12.0 | 2026-09-09 |
|
|
32
25
|
| The Firefox family's default profile, the one profiles.ini names | 0.13.0 | 2026-09-09 |
|
|
33
26
|
| Firefox and Tor Browser bookmarks with their folders | 0.14.0 | 2026-09-09 |
|
|
27
|
+
| `Browser::Bookmarks#tree`, the bookmarks as a tree, folders and all | 0.17.0 | 2026-10-03 |
|
|
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 |
|
|
34
31
|
|
|
35
32
|
|
|
36
33
|
## Capabilities, per browser, and when each arrived
|
|
@@ -46,6 +43,53 @@ The README's table, with each cell holding the version at which it became true.
|
|
|
46
43
|
| Safari | 0.6.1 | 0.4.0 | 0.10.0 | none | none |
|
|
47
44
|
| Tor Browser | 0.7.0 | 0.7.0 | 0.14.0 | 0.7.0 | 0.13.0 |
|
|
48
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
|
+
|
|
69
|
+
## 20261003
|
|
70
|
+
|
|
71
|
+
0.17.0: + Browser::Bookmarks#tree, the bookmark tree; + Browser::Base#profile_path, the profile directory.
|
|
72
|
+
|
|
73
|
+
1. + Browser::Bookmarks#tree: the root Browser::Bookmark, which results holds and nothing outside could reach.
|
|
74
|
+
2. to_objects flattens the tree to its leaves, so no folder was readable anywhere.
|
|
75
|
+
3. Browser::Bookmark#name goes with them, unreachable since it arrived at 0.14.0 for writing back into a browser.
|
|
76
|
+
4. + Browser::Base.profile_path(profile_name:): profiles_path joined to the profile name.
|
|
77
|
+
5. + Browser::Base#profile_path: the same for an instance, holding nothing, profile_name having memoised the lookup.
|
|
78
|
+
6. Safari needs no override of its own: its profiles_path is nil, and a nil profiles_path is a nil profile_path.
|
|
79
|
+
7. A family implementing neither root_path nor profiles_path raises NotImplementedError through the guard it already carries.
|
|
80
|
+
8. + test/Browser/Brave_test.rb, Chrome_test.rb, Chromium_test.rb, Firefox_test.rb, Safari_test.rb, TorBrowser_test.rb: .profile_path and #profile_path.
|
|
81
|
+
9. + test/Browser/Chromium_test.rb, Safari_test.rb, Firefox_test.rb: #tree, one test per format read.
|
|
82
|
+
10. ~ test/Browser/Firefox_test.rb: + #name reached through the tree, Firefox's roots being the titles which differ from their names.
|
|
83
|
+
11. ~ browser.rb.gemspec: the description cut to one sentence; the rest restated the README.
|
|
84
|
+
12. ~ README.md: + tree and profile_path.
|
|
85
|
+
13. ~ ROADMAP.md: driving a browser, with the profile path no longer in the way.
|
|
86
|
+
14. ~ ROADMAP.md: + the require path.
|
|
87
|
+
15. ~ TODO: - the bookmark tree and the profile directory, both done.
|
|
88
|
+
16. ~ TODO: + the gemspec's dependencies derived from lib's requires.
|
|
89
|
+
17. ~ CHANGELOG: - How this history is kept.
|
|
90
|
+
18. ~ Browser::VERSION: /0.16.0/0.17.0/
|
|
91
|
+
|
|
92
|
+
|
|
49
93
|
## 20260925
|
|
50
94
|
|
|
51
95
|
0.16.0: ~ Browser::Rendering::CSV: Use CSV from the standard library; ~ Browser::Bookmarks.from_sqlite: Build the Bookmark object directly; ~ ROADMAP.md and TODO tidied.
|
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
|
|
|
@@ -39,9 +39,12 @@ require 'browser'
|
|
|
39
39
|
|
|
40
40
|
chrome = Browser.new(:chrome)
|
|
41
41
|
chrome.bookmarks.to_objects # => [{title:, url:, folder:}, ...]
|
|
42
|
+
chrome.bookmarks.tree # => Browser::Bookmark, the folders and all
|
|
42
43
|
chrome.bookmarks.to_csv # title,url,folder rows
|
|
43
44
|
chrome.bookmarks.to_json
|
|
44
|
-
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
|
|
47
|
+
chrome.profile_path # => the directory the profile sits in
|
|
45
48
|
```
|
|
46
49
|
|
|
47
50
|
Name a browser by string or symbol, in any case:
|
|
@@ -67,6 +70,21 @@ The renderers are `to_objects` (an array of `{title:, url:, folder:}`), `to_csv`
|
|
|
67
70
|
`to_json` and `to_plist`. `dump(format:, path:, filename:)` writes one to a file and
|
|
68
71
|
returns the path. `readable?` says whether the data can be read right now.
|
|
69
72
|
|
|
73
|
+
Underneath the renderers, `bookmarks.tree` is the bookmarks as `Browser::Bookmark`:
|
|
74
|
+
a titleless root whose children are the browser's own roots, each folder holding its
|
|
75
|
+
children. The renderers flatten that to leaves and drop the folders, so the tree is
|
|
76
|
+
where a folder, or `Bookmark#name`, is to be had.
|
|
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
|
+
|
|
85
|
+
`profile_path` is the directory the profile sits in, which a Selenium front end wants
|
|
86
|
+
in place of a throwaway one. Safari, having no profiles, answers `nil`.
|
|
87
|
+
|
|
70
88
|
## Capabilities
|
|
71
89
|
|
|
72
90
|
| browser | bookmarks read from | history read from | folders | profile |
|
|
@@ -82,6 +100,11 @@ returns the path. `readable?` says whether the data can be read right now.
|
|
|
82
100
|
|
|
83
101
|
- **macOS only, for now.** Every location is a macOS path; Linux and Windows are on
|
|
84
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.
|
|
85
108
|
- **A running browser locks its database.** History, and Firefox's bookmarks, are
|
|
86
109
|
read from SQLite, which the browser locks while it is open — so reading a browser
|
|
87
110
|
you are using raises `Browser::Unreadable`. Ask `readable?` first, or quit it.
|
data/browser.rb.gemspec
CHANGED
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.version = Browser::VERSION
|
|
18
18
|
|
|
19
19
|
spec.summary = "Read web browser bookmarks and history with Ruby."
|
|
20
|
-
spec.description = "Read the bookmarks and history
|
|
20
|
+
spec.description = "Read the bookmarks and history for Brave, Chrome, Chromium, Firefox, Safari and Tor Browser, and render them to CSV, JSON or a property list."
|
|
21
21
|
|
|
22
22
|
spec.author = 'thoran'
|
|
23
23
|
spec.email = 'code@thoran.com'
|
data/lib/Browser/Base.rb
CHANGED
|
@@ -10,6 +10,15 @@ class Browser
|
|
|
10
10
|
def default_profile_name
|
|
11
11
|
self::DEFAULT_PROFILE_NAME
|
|
12
12
|
end
|
|
13
|
+
|
|
14
|
+
# The directory the profile sits in, which a Selenium front end wants in place
|
|
15
|
+
# of a throwaway one. A browser which keeps no profiles has no such directory,
|
|
16
|
+
# and says so with nil rather than with a path.
|
|
17
|
+
def profile_path(profile_name: nil)
|
|
18
|
+
return nil unless profiles_path
|
|
19
|
+
profile_name ||= default_profile_name
|
|
20
|
+
File.expand_path("#{profiles_path}/#{profile_name}")
|
|
21
|
+
end
|
|
13
22
|
end
|
|
14
23
|
|
|
15
24
|
def bookmarks
|
|
@@ -35,6 +44,12 @@ class Browser
|
|
|
35
44
|
@history_location ||= self.class.history_location(profile_name: profile_name)
|
|
36
45
|
end
|
|
37
46
|
|
|
47
|
+
# Derived from the profile name alone, which has done any looking up already, and
|
|
48
|
+
# never given, so there is nothing here to hold on to.
|
|
49
|
+
def profile_path
|
|
50
|
+
self.class.profile_path(profile_name: profile_name)
|
|
51
|
+
end
|
|
52
|
+
|
|
38
53
|
def name
|
|
39
54
|
self.class.to_s.split('::').last
|
|
40
55
|
end
|
data/lib/Browser/Bookmarks.rb
CHANGED
|
@@ -89,6 +89,13 @@ class Browser
|
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
+
# The tree as the browser keeps it: a titleless root whose children are the
|
|
93
|
+
# browser's own roots. to_objects flattens it and keeps only the leaves, so the
|
|
94
|
+
# folders, and Bookmark#name with them, are reachable nowhere else.
|
|
95
|
+
def tree
|
|
96
|
+
results
|
|
97
|
+
end
|
|
98
|
+
|
|
92
99
|
def to_objects
|
|
93
100
|
results.flatten
|
|
94
101
|
end
|
|
@@ -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
|
|
@@ -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
|
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)
|
|
@@ -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
|
data/lib/Browser/VERSION.rb
CHANGED
|
@@ -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
|
data/test/Browser/Brave_test.rb
CHANGED
|
@@ -44,6 +44,14 @@ describe Browser::Brave do
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
describe '.profile_path' do
|
|
48
|
+
let(:expected_profile_path){File.expand_path('~/Library/Application Support/BraveSoftware/Brave-Browser/Default')}
|
|
49
|
+
|
|
50
|
+
it "contains the correct profile path" do
|
|
51
|
+
expect(subject.profile_path).to eq(expected_profile_path)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
47
55
|
describe ".bookmarks_sql" do
|
|
48
56
|
it "returns the bookmarks sql" do
|
|
49
57
|
expect(subject.send(:bookmarks_sql)).to be_nil
|
|
@@ -64,8 +72,8 @@ describe Browser::Brave do
|
|
|
64
72
|
let(:default_profile_name){'Default'}
|
|
65
73
|
let(:expected_history) do
|
|
66
74
|
[
|
|
67
|
-
{
|
|
68
|
-
{
|
|
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)},
|
|
69
77
|
]
|
|
70
78
|
end
|
|
71
79
|
|
|
@@ -93,6 +101,12 @@ describe Browser::Brave do
|
|
|
93
101
|
end
|
|
94
102
|
end
|
|
95
103
|
|
|
104
|
+
describe "#profile_path" do
|
|
105
|
+
it "returns the directory the profile sits in" do
|
|
106
|
+
expect(subject.profile_path).to eq(File.expand_path('~/Library/Application Support/BraveSoftware/Brave-Browser/Default'))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
96
110
|
let(:expected_bookmarks) do
|
|
97
111
|
[
|
|
98
112
|
{title: 'Welcome to Brave', url: 'chrome://welcome/', folder: 'Bookmarks bar'},
|
|
@@ -115,7 +129,7 @@ describe Browser::Brave do
|
|
|
115
129
|
end
|
|
116
130
|
|
|
117
131
|
it "returns the history" do
|
|
118
|
-
expect(subject.history.
|
|
132
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
119
133
|
end
|
|
120
134
|
end
|
|
121
135
|
|
data/test/Browser/Chrome_test.rb
CHANGED
|
@@ -44,6 +44,14 @@ describe Browser::Chrome do
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
describe '.profile_path' do
|
|
48
|
+
let(:expected_profile_path){File.expand_path('~/Library/Application Support/Google/Chrome/Default')}
|
|
49
|
+
|
|
50
|
+
it "contains the correct profile path" do
|
|
51
|
+
expect(subject.profile_path).to eq(expected_profile_path)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
47
55
|
describe ".bookmarks_sql" do
|
|
48
56
|
it "returns the bookmarks sql" do
|
|
49
57
|
expect(subject.send(:bookmarks_sql)).to be_nil
|
|
@@ -64,8 +72,8 @@ describe Browser::Chrome do
|
|
|
64
72
|
let(:default_profile_name){'Default'}
|
|
65
73
|
let(:expected_history) do
|
|
66
74
|
[
|
|
67
|
-
{
|
|
68
|
-
{
|
|
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)},
|
|
69
77
|
]
|
|
70
78
|
end
|
|
71
79
|
|
|
@@ -93,6 +101,12 @@ describe Browser::Chrome do
|
|
|
93
101
|
end
|
|
94
102
|
end
|
|
95
103
|
|
|
104
|
+
describe "#profile_path" do
|
|
105
|
+
it "returns the directory the profile sits in" do
|
|
106
|
+
expect(subject.profile_path).to eq(File.expand_path('~/Library/Application Support/Google/Chrome/Default'))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
96
110
|
let(:expected_bookmarks) do
|
|
97
111
|
[
|
|
98
112
|
{title: 'Home', url: 'https://www.chromium.org/chromium-projects/', folder: 'Bookmarks Bar'},
|
|
@@ -115,7 +129,7 @@ describe Browser::Chrome do
|
|
|
115
129
|
end
|
|
116
130
|
|
|
117
131
|
it "returns the history" do
|
|
118
|
-
expect(subject.history.
|
|
132
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
119
133
|
end
|
|
120
134
|
end
|
|
121
135
|
|
|
@@ -44,6 +44,18 @@ describe Browser::Chromium do
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
describe '.profile_path' do
|
|
48
|
+
let(:expected_profile_path){File.expand_path('~/Library/Application Support/Chromium/Default')}
|
|
49
|
+
|
|
50
|
+
it "contains the correct profile path" do
|
|
51
|
+
expect(subject.profile_path).to eq(expected_profile_path)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "takes a named profile in place of the default" do
|
|
55
|
+
expect(subject.profile_path(profile_name: 'Profile 1')).to eq(File.expand_path('~/Library/Application Support/Chromium/Profile 1'))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
47
59
|
describe ".bookmarks_sql" do
|
|
48
60
|
it "returns the bookmarks sql" do
|
|
49
61
|
expect(subject.send(:bookmarks_sql)).to be_nil
|
|
@@ -64,8 +76,8 @@ describe Browser::Chromium do
|
|
|
64
76
|
let(:default_profile_name){'Default'}
|
|
65
77
|
let(:expected_history) do
|
|
66
78
|
[
|
|
67
|
-
{
|
|
68
|
-
{
|
|
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)},
|
|
69
81
|
]
|
|
70
82
|
end
|
|
71
83
|
|
|
@@ -93,6 +105,12 @@ describe Browser::Chromium do
|
|
|
93
105
|
end
|
|
94
106
|
end
|
|
95
107
|
|
|
108
|
+
describe "#profile_path" do
|
|
109
|
+
it "returns the directory the profile sits in" do
|
|
110
|
+
expect(subject.profile_path).to eq(File.expand_path('~/Library/Application Support/Chromium/Default'))
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
96
114
|
let(:expected_bookmarks) do
|
|
97
115
|
[
|
|
98
116
|
{title: 'Home', url: 'https://www.chromium.org/chromium-projects/', folder: 'Bookmarks Bar'},
|
|
@@ -107,6 +125,16 @@ describe Browser::Chromium do
|
|
|
107
125
|
it "returns the bookmarks" do
|
|
108
126
|
expect(subject.bookmarks.to_objects).to eq(expected_bookmarks)
|
|
109
127
|
end
|
|
128
|
+
|
|
129
|
+
it "returns the tree, whose children are the browser's roots" do
|
|
130
|
+
expect(subject.bookmarks.tree).to be_a(Browser::Bookmark)
|
|
131
|
+
expect(subject.bookmarks.tree.children.collect(&:title)).to eq(['Bookmarks Bar', 'Other Bookmarks', 'Mobile Bookmarks'])
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "keeps in the tree the folders to_objects drops, empty ones among them" do
|
|
135
|
+
expect(subject.bookmarks.tree.children.count(&:folder?)).to eq(3)
|
|
136
|
+
expect(subject.bookmarks.to_objects.length).to eq(1)
|
|
137
|
+
end
|
|
110
138
|
end
|
|
111
139
|
|
|
112
140
|
describe "#history" do
|
|
@@ -115,7 +143,15 @@ describe Browser::Chromium do
|
|
|
115
143
|
end
|
|
116
144
|
|
|
117
145
|
it "returns the history" do
|
|
118
|
-
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)
|
|
119
155
|
end
|
|
120
156
|
end
|
|
121
157
|
|
|
@@ -89,6 +89,14 @@ describe Browser::Firefox do
|
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
+
describe '.profile_path' do
|
|
93
|
+
let(:expected_profile_path){File.expand_path('~/Library/Application Support/Firefox/Profiles/abcd1234.default-release')}
|
|
94
|
+
|
|
95
|
+
it "contains the correct profile path" do
|
|
96
|
+
expect(subject.profile_path(profile_name: profile_name)).to eq(expected_profile_path)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
92
100
|
describe ".bookmarks_sql" do
|
|
93
101
|
it "returns the bookmarks sql" do
|
|
94
102
|
expect(subject.send(:bookmarks_sql)).to eq(expected_bookmarks_sql)
|
|
@@ -108,7 +116,7 @@ describe Browser::Firefox do
|
|
|
108
116
|
let(:browser_name){'Firefox'}
|
|
109
117
|
let(:expected_history) do
|
|
110
118
|
[
|
|
111
|
-
{
|
|
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)},
|
|
112
120
|
]
|
|
113
121
|
end
|
|
114
122
|
|
|
@@ -136,6 +144,12 @@ describe Browser::Firefox do
|
|
|
136
144
|
end
|
|
137
145
|
end
|
|
138
146
|
|
|
147
|
+
describe "#profile_path" do
|
|
148
|
+
it "returns the directory the profile sits in" do
|
|
149
|
+
expect(subject.profile_path).to eq(File.expand_path('~/Library/Application Support/Firefox/Profiles/abcd1234.default-release'))
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
139
153
|
let(:expected_bookmarks) do
|
|
140
154
|
[
|
|
141
155
|
{title: 'Get Help', url: 'https://support.mozilla.org/products/firefox', folder: 'Bookmarks Menu/Mozilla Firefox'},
|
|
@@ -154,6 +168,15 @@ describe Browser::Firefox do
|
|
|
154
168
|
it "returns the bookmarks" do
|
|
155
169
|
expect(subject.bookmarks.to_objects).to eq(expected_bookmarks)
|
|
156
170
|
end
|
|
171
|
+
|
|
172
|
+
it "returns the tree, whose children are the browser's roots" do
|
|
173
|
+
expect(subject.bookmarks.tree).to be_a(Browser::Bookmark)
|
|
174
|
+
expect(subject.bookmarks.tree.children.collect(&:title)).to eq(['Bookmarks Menu', 'Bookmarks Toolbar', 'Other Bookmarks', 'Mobile Bookmarks'])
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "reaches Bookmark#name, which the tree alone carries" do
|
|
178
|
+
expect(subject.bookmarks.tree.children.collect(&:name)).to eq(%w{menu toolbar unfiled mobile})
|
|
179
|
+
end
|
|
157
180
|
end
|
|
158
181
|
|
|
159
182
|
describe "#history" do
|
|
@@ -162,7 +185,14 @@ describe Browser::Firefox do
|
|
|
162
185
|
end
|
|
163
186
|
|
|
164
187
|
it "returns the history" do
|
|
165
|
-
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)
|
|
166
196
|
end
|
|
167
197
|
end
|
|
168
198
|
|
data/test/Browser/Safari_test.rb
CHANGED
|
@@ -42,6 +42,12 @@ describe Browser::Safari do
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
describe '.profile_path' do
|
|
46
|
+
it "has no profile path, Safari having no profiles" do
|
|
47
|
+
expect(subject.profile_path).to be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
45
51
|
describe ".bookmarks_sql" do
|
|
46
52
|
it "returns the bookmarks sql" do
|
|
47
53
|
expect(subject.send(:bookmarks_sql)).to be_nil
|
|
@@ -61,8 +67,8 @@ describe Browser::Safari do
|
|
|
61
67
|
let(:browser_name){'Safari'}
|
|
62
68
|
let(:expected_history) do
|
|
63
69
|
[
|
|
64
|
-
{
|
|
65
|
-
{
|
|
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)},
|
|
66
72
|
]
|
|
67
73
|
end
|
|
68
74
|
|
|
@@ -90,6 +96,12 @@ describe Browser::Safari do
|
|
|
90
96
|
end
|
|
91
97
|
end
|
|
92
98
|
|
|
99
|
+
describe "#profile_path" do
|
|
100
|
+
it "has no profile path, Safari having no profiles" do
|
|
101
|
+
expect(subject.profile_path).to be_nil
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
93
105
|
let(:expected_bookmarks) do
|
|
94
106
|
[
|
|
95
107
|
{title: 'Apple', url: 'https://www.apple.com/', folder: 'BookmarksBar'},
|
|
@@ -116,6 +128,11 @@ describe Browser::Safari do
|
|
|
116
128
|
it "returns the bookmarks" do
|
|
117
129
|
expect(subject.bookmarks.to_objects).to eq(expected_bookmarks)
|
|
118
130
|
end
|
|
131
|
+
|
|
132
|
+
it "returns the tree, whose children are the browser's roots" do
|
|
133
|
+
expect(subject.bookmarks.tree).to be_a(Browser::Bookmark)
|
|
134
|
+
expect(subject.bookmarks.tree.children.collect(&:title)).to eq(['BookmarksBar', 'BookmarksMenu', 'Home \ Anthropic'])
|
|
135
|
+
end
|
|
119
136
|
end
|
|
120
137
|
|
|
121
138
|
describe "#history" do
|
|
@@ -124,7 +141,15 @@ describe Browser::Safari do
|
|
|
124
141
|
end
|
|
125
142
|
|
|
126
143
|
it "returns the history" do
|
|
127
|
-
expect(subject.history.
|
|
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)
|
|
128
153
|
end
|
|
129
154
|
end
|
|
130
155
|
|
|
@@ -46,6 +46,14 @@ describe Browser::TorBrowser do
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
describe '.profile_path' do
|
|
50
|
+
let(:expected_profile_path){File.expand_path('~/Library/Application Support/TorBrowser-Data/Browser/abcd1234.default')}
|
|
51
|
+
|
|
52
|
+
it "contains the correct profile path" do
|
|
53
|
+
expect(subject.profile_path(profile_name: profile_name)).to eq(expected_profile_path)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
49
57
|
describe ".bookmarks_sql" do
|
|
50
58
|
it "returns the bookmarks sql" do
|
|
51
59
|
expect(subject.send(:bookmarks_sql)).to eq(expected_bookmarks_sql)
|
|
@@ -65,7 +73,7 @@ describe Browser::TorBrowser do
|
|
|
65
73
|
let(:browser_name){'TorBrowser'}
|
|
66
74
|
let(:expected_history) do
|
|
67
75
|
[
|
|
68
|
-
{
|
|
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)},
|
|
69
77
|
]
|
|
70
78
|
end
|
|
71
79
|
|
|
@@ -93,6 +101,12 @@ describe Browser::TorBrowser do
|
|
|
93
101
|
end
|
|
94
102
|
end
|
|
95
103
|
|
|
104
|
+
describe "#profile_path" do
|
|
105
|
+
it "returns the directory the profile sits in" do
|
|
106
|
+
expect(subject.profile_path).to eq(File.expand_path('~/Library/Application Support/TorBrowser-Data/Browser/abcd1234.default'))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
96
110
|
let(:expected_bookmarks) do
|
|
97
111
|
[
|
|
98
112
|
{title: 'Get Help', url: 'https://support.mozilla.org/products/firefox', folder: 'Bookmarks Menu/Mozilla Firefox'},
|
|
@@ -119,7 +133,7 @@ describe Browser::TorBrowser do
|
|
|
119
133
|
end
|
|
120
134
|
|
|
121
135
|
it "returns the history" do
|
|
122
|
-
expect(subject.history.
|
|
136
|
+
expect(subject.history.to_objects).to eq(expected_history)
|
|
123
137
|
end
|
|
124
138
|
end
|
|
125
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.
|
|
4
|
+
version: 0.18.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -121,10 +121,8 @@ dependencies:
|
|
|
121
121
|
- - ">="
|
|
122
122
|
- !ruby/object:Gem::Version
|
|
123
123
|
version: '0'
|
|
124
|
-
description: Read the bookmarks and history
|
|
125
|
-
|
|
126
|
-
or a property list. Bookmarks come through as one representation whatever the browser;
|
|
127
|
-
history as each browser stores it.
|
|
124
|
+
description: Read the bookmarks and history for Brave, Chrome, Chromium, Firefox,
|
|
125
|
+
Safari and Tor Browser, and render them to CSV, JSON or a property list.
|
|
128
126
|
email: code@thoran.com
|
|
129
127
|
executables: []
|
|
130
128
|
extensions: []
|
|
@@ -151,6 +149,7 @@ files:
|
|
|
151
149
|
- lib/Browser/TorBrowser.rb
|
|
152
150
|
- lib/Browser/Unreadable.rb
|
|
153
151
|
- lib/Browser/VERSION.rb
|
|
152
|
+
- lib/Browser/Visit.rb
|
|
154
153
|
- lib/browser-classes.rb
|
|
155
154
|
- lib/browser.rb
|
|
156
155
|
- test/Browser/Bookmark_test.rb
|
|
@@ -161,6 +160,7 @@ files:
|
|
|
161
160
|
- test/Browser/Rendering_test.rb
|
|
162
161
|
- test/Browser/Safari_test.rb
|
|
163
162
|
- test/Browser/TorBrowser_test.rb
|
|
163
|
+
- test/Browser/Visit_test.rb
|
|
164
164
|
- test/browser_test.rb
|
|
165
165
|
- test/fixtures/Brave_bookmarks.json
|
|
166
166
|
- test/fixtures/ChromiumBased_history.sqlite
|