browser.rb 0.16.0 → 0.17.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: 6d021a1b082f2676924ac7934a2c07630e3e1b9acf0fc6cc5199c089fcdf04e8
4
- data.tar.gz: de83b9b9a841bcd7b1c8c22184d9b1d2f2e2f8a1c1010c57a15a1122ec8b2984
3
+ metadata.gz: 6736107069b9106898aa3d0cd4eff7cc871accd26202c2216852dae6f1de78a4
4
+ data.tar.gz: 27905d0383d166591313067fea7240b69198e66e21ec43517ea29170749fe55b
5
5
  SHA512:
6
- metadata.gz: 2b57c7138e471c8bff5954f33d6252fe1584fd6514836d03dd412b1b260726003894e3d8455c02e4218e952a8344ba750821724370461a0bcd6e29e576ab1ea4
7
- data.tar.gz: c59caa0712477eb8bf6ec7fe5731e41b50bfa8a5b4fa23b5e0e943ce056e70f41a1ed911551a716b391d25f01aa77bb777aacd812a781c0f1eceb77f7a0eadd8
6
+ metadata.gz: e4a5cd271f4d2894e8967a806e16ecd8e592635ab09dc7b012de8bd9d056f909d06fe451d8fd4d404e3b2cc0d5c7ff63dcb5abe29c5be3330d26b18ab2b050f0
7
+ data.tar.gz: ef6ef839d154af43f6d8bbabdfa7c286fa6f51b6ccbed710c4bb3502a179ebf33f944f3ac3e94f3fd4b2ea2848b7b8b159ab0e399aa009646dadc9fdf14aa5c5
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,8 @@ 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 |
34
29
 
35
30
 
36
31
  ## Capabilities, per browser, and when each arrived
@@ -46,6 +41,30 @@ The README's table, with each cell holding the version at which it became true.
46
41
  | Safari | 0.6.1 | 0.4.0 | 0.10.0 | none | none |
47
42
  | Tor Browser | 0.7.0 | 0.7.0 | 0.14.0 | 0.7.0 | 0.13.0 |
48
43
 
44
+ ## 20261003
45
+
46
+ 0.17.0: + Browser::Bookmarks#tree, the bookmark tree; + Browser::Base#profile_path, the profile directory.
47
+
48
+ 1. + Browser::Bookmarks#tree: the root Browser::Bookmark, which results holds and nothing outside could reach.
49
+ 2. to_objects flattens the tree to its leaves, so no folder was readable anywhere.
50
+ 3. Browser::Bookmark#name goes with them, unreachable since it arrived at 0.14.0 for writing back into a browser.
51
+ 4. + Browser::Base.profile_path(profile_name:): profiles_path joined to the profile name.
52
+ 5. + Browser::Base#profile_path: the same for an instance, holding nothing, profile_name having memoised the lookup.
53
+ 6. Safari needs no override of its own: its profiles_path is nil, and a nil profiles_path is a nil profile_path.
54
+ 7. A family implementing neither root_path nor profiles_path raises NotImplementedError through the guard it already carries.
55
+ 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.
56
+ 9. + test/Browser/Chromium_test.rb, Safari_test.rb, Firefox_test.rb: #tree, one test per format read.
57
+ 10. ~ test/Browser/Firefox_test.rb: + #name reached through the tree, Firefox's roots being the titles which differ from their names.
58
+ 11. ~ browser.rb.gemspec: the description cut to one sentence; the rest restated the README.
59
+ 12. ~ README.md: + tree and profile_path.
60
+ 13. ~ ROADMAP.md: driving a browser, with the profile path no longer in the way.
61
+ 14. ~ ROADMAP.md: + the require path.
62
+ 15. ~ TODO: - the bookmark tree and the profile directory, both done.
63
+ 16. ~ TODO: + the gemspec's dependencies derived from lib's requires.
64
+ 17. ~ CHANGELOG: - How this history is kept.
65
+ 18. ~ Browser::VERSION: /0.16.0/0.17.0/
66
+
67
+
49
68
  ## 20260925
50
69
 
51
70
  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
@@ -39,9 +39,11 @@ 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
45
  chrome.history.to_objects
46
+ chrome.profile_path # => the directory the profile sits in
45
47
  ```
46
48
 
47
49
  Name a browser by string or symbol, in any case:
@@ -67,6 +69,14 @@ The renderers are `to_objects` (an array of `{title:, url:, folder:}`), `to_csv`
67
69
  `to_json` and `to_plist`. `dump(format:, path:, filename:)` writes one to a file and
68
70
  returns the path. `readable?` says whether the data can be read right now.
69
71
 
72
+ Underneath the renderers, `bookmarks.tree` is the bookmarks as `Browser::Bookmark`:
73
+ a titleless root whose children are the browser's own roots, each folder holding its
74
+ children. The renderers flatten that to leaves and drop the folders, so the tree is
75
+ where a folder, or `Bookmark#name`, is to be had.
76
+
77
+ `profile_path` is the directory the profile sits in, which a Selenium front end wants
78
+ in place of a throwaway one. Safari, having no profiles, answers `nil`.
79
+
70
80
  ## Capabilities
71
81
 
72
82
  | browser | bookmarks read from | history read from | folders | profile |
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 of the web browsers on a machine, Brave, Chrome, Chromium, Firefox, Safari and Tor Browser, and render them to CSV, JSON or a property list. Bookmarks come through as one representation whatever the browser; history as each browser stores it."
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
@@ -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
@@ -2,5 +2,5 @@
2
2
  # Browser::VERSION
3
3
 
4
4
  class Browser
5
- VERSION = '0.16.0'
5
+ VERSION = '0.17.0'
6
6
  end
@@ -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
@@ -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'},
@@ -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
@@ -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'},
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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'},
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.16.0
4
+ version: 0.17.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 of the web browsers on a machine, Brave,
125
- Chrome, Chromium, Firefox, Safari and Tor Browser, and render them to CSV, JSON
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: []