chrome-tools 1.1.6 → 1.1.8
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.
- package/dist/bin/cli.js +556 -1
- package/dist/src/core/browsers.d.ts +7 -3
- package/dist/src/core/browsers.js +186 -1
- package/dist/src/core/chrome.d.ts +6 -4
- package/dist/src/core/chrome.js +240 -1
- package/dist/src/core/crypto.d.ts +1 -1
- package/dist/src/core/crypto.js +113 -1
- package/dist/src/core/db.d.ts +4 -2
- package/dist/src/core/db.js +90 -1
- package/dist/src/core/keychain.js +191 -1
- package/dist/src/core/limit.d.ts +4 -0
- package/dist/src/core/limit.js +12 -0
- package/dist/src/core/platform/darwin.js +31 -1
- package/dist/src/core/platform/index.d.ts +4 -3
- package/dist/src/core/platform/index.js +69 -1
- package/dist/src/core/platform/linux.js +64 -1
- package/dist/src/core/platform/types.d.ts +3 -2
- package/dist/src/core/platform/types.js +1 -1
- package/dist/src/core/platform/win32.js +114 -1
- package/dist/src/core/sql.d.ts +2 -0
- package/dist/src/core/sql.js +4 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +34 -1
- package/dist/src/modules/autofill.d.ts +7 -15
- package/dist/src/modules/autofill.js +170 -1
- package/dist/src/modules/bookmarks.d.ts +3 -5
- package/dist/src/modules/bookmarks.js +83 -1
- package/dist/src/modules/cookies.d.ts +3 -5
- package/dist/src/modules/cookies.js +157 -1
- package/dist/src/modules/downloads.d.ts +3 -5
- package/dist/src/modules/downloads.js +80 -1
- package/dist/src/modules/extensions.d.ts +3 -5
- package/dist/src/modules/extensions.js +71 -1
- package/dist/src/modules/history.d.ts +5 -10
- package/dist/src/modules/history.js +83 -1
- package/dist/src/modules/local-storage.d.ts +3 -5
- package/dist/src/modules/local-storage.js +455 -1
- package/dist/src/modules/passwords.d.ts +3 -5
- package/dist/src/modules/passwords.js +131 -1
- package/dist/src/modules/search-engines.d.ts +3 -5
- package/dist/src/modules/search-engines.js +38 -1
- package/dist/src/modules/top-sites.d.ts +3 -5
- package/dist/src/modules/top-sites.js +33 -1
- package/package.json +14 -12
package/dist/src/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* const profiles = discoverProfiles();
|
|
12
12
|
*/
|
|
13
13
|
export { getDefaultChromeDir, discoverProfiles, getProfileMetadata, getProfileStates, resolveProfilePath, resolveTargetProfiles, detectInstalledBrowsers, type DiscoveredProfile, type ProfileMetadata, type ProfileState, type ResolveProfilesOptions, type InstalledBrowser, } from "./core/chrome.js";
|
|
14
|
-
export { BROWSERS, listBrowsers, resolveBrowser, getActiveBrowser, setActiveBrowser, type BrowserId, type BrowserDescriptor, } from "./core/browsers.js";
|
|
14
|
+
export { BROWSERS, listBrowsers, resolveBrowser, requireBrowser, getActiveBrowser, setActiveBrowser, type BrowserId, type BrowserDescriptor, } from "./core/browsers.js";
|
|
15
15
|
export { selectPlatform, getPlatformChromeDir, deriveEncryptionKey, decryptValue, decryptValueBuffer, clearKeyCache, type ChromePlatform, } from "./core/platform/index.js";
|
|
16
16
|
export { getKeychainPassword, getChromeKeychainPassword, clearKeychainCache, setKeychainPasswordProvider, getKeychainPasswordProvider, type KeychainPasswordProvider, } from "./core/keychain.js";
|
|
17
17
|
export { chromeTimeToDate, } from "./core/crypto.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* chrome-tools — Public API
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports all feature modules for use as a Node.js library.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { getPasswords, getBookmarks, discoverProfiles } from 'chrome-tools';
|
|
8
|
+
*
|
|
9
|
+
* const passwords = getPasswords({ profile: 'Default' });
|
|
10
|
+
* const bookmarks = getBookmarks({ search: 'github' });
|
|
11
|
+
* const profiles = discoverProfiles();
|
|
12
|
+
*/
|
|
13
|
+
// Core utilities
|
|
14
|
+
export { getDefaultChromeDir, discoverProfiles, getProfileMetadata, getProfileStates, resolveProfilePath, resolveTargetProfiles, detectInstalledBrowsers, } from "./core/chrome.js";
|
|
15
|
+
// Browser registry & selection (all Chromium-based browsers)
|
|
16
|
+
export { BROWSERS, listBrowsers, resolveBrowser, requireBrowser, getActiveBrowser, setActiveBrowser, } from "./core/browsers.js";
|
|
17
|
+
// Platform-aware decryption (macOS / Windows / Linux)
|
|
18
|
+
export { selectPlatform, getPlatformChromeDir, deriveEncryptionKey, decryptValue, decryptValueBuffer, clearKeyCache, } from "./core/platform/index.js";
|
|
19
|
+
// macOS Keychain helpers (macOS-only). `getKeychainPassword` takes a Safe
|
|
20
|
+
// Storage service name; `getChromeKeychainPassword` is the Chrome-specific alias.
|
|
21
|
+
export { getKeychainPassword, getChromeKeychainPassword, clearKeychainCache, setKeychainPasswordProvider, getKeychainPasswordProvider, } from "./core/keychain.js";
|
|
22
|
+
export { chromeTimeToDate, } from "./core/crypto.js";
|
|
23
|
+
export { queryDatabase, tableExists, } from "./core/db.js";
|
|
24
|
+
// Feature modules
|
|
25
|
+
export { getPasswords } from "./modules/passwords.js";
|
|
26
|
+
export { getBookmarks } from "./modules/bookmarks.js";
|
|
27
|
+
export { getHistory, getSearchTerms } from "./modules/history.js";
|
|
28
|
+
export { getCookies } from "./modules/cookies.js";
|
|
29
|
+
export { getLocalStorage } from "./modules/local-storage.js";
|
|
30
|
+
export { getAutofillEntries, getCreditCards, getAddresses } from "./modules/autofill.js";
|
|
31
|
+
export { getDownloads } from "./modules/downloads.js";
|
|
32
|
+
export { getExtensions } from "./modules/extensions.js";
|
|
33
|
+
export { getSearchEngines } from "./modules/search-engines.js";
|
|
34
|
+
export { getTopSites } from "./modules/top-sites.js";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
profile?: string;
|
|
4
|
-
browser?: string;
|
|
1
|
+
import { type ResolveProfilesOptions } from "../core/chrome.js";
|
|
2
|
+
export interface AutofillOptions extends ResolveProfilesOptions {
|
|
5
3
|
search?: string;
|
|
6
4
|
limit?: number;
|
|
7
5
|
}
|
|
@@ -13,10 +11,7 @@ export interface AutofillEntry {
|
|
|
13
11
|
dateLastUsed: string;
|
|
14
12
|
count: number;
|
|
15
13
|
}
|
|
16
|
-
export interface CreditCardOptions {
|
|
17
|
-
chromeDir?: string;
|
|
18
|
-
profile?: string;
|
|
19
|
-
browser?: string;
|
|
14
|
+
export interface CreditCardOptions extends ResolveProfilesOptions {
|
|
20
15
|
decryptionKey?: Buffer;
|
|
21
16
|
}
|
|
22
17
|
export interface CreditCardEntry {
|
|
@@ -31,10 +26,7 @@ export interface CreditCardEntry {
|
|
|
31
26
|
useCount: number;
|
|
32
27
|
dateModified: string;
|
|
33
28
|
}
|
|
34
|
-
export interface AddressOptions {
|
|
35
|
-
chromeDir?: string;
|
|
36
|
-
profile?: string;
|
|
37
|
-
browser?: string;
|
|
29
|
+
export interface AddressOptions extends ResolveProfilesOptions {
|
|
38
30
|
}
|
|
39
31
|
export interface AddressEntry {
|
|
40
32
|
profile: string;
|
|
@@ -58,7 +50,7 @@ export interface AddressEntry {
|
|
|
58
50
|
* @param options - Filtering and targeting options.
|
|
59
51
|
* @returns Array of autofill entries.
|
|
60
52
|
*/
|
|
61
|
-
export declare function getAutofillEntries({ chromeDir, profile, browser, search, limit, }?: AutofillOptions): AutofillEntry[];
|
|
53
|
+
export declare function getAutofillEntries({ chromeDir, profilePath, profile, browser, search, limit, }?: AutofillOptions): AutofillEntry[];
|
|
62
54
|
/**
|
|
63
55
|
* Retrieves saved credit cards from Chrome's Web Data database.
|
|
64
56
|
* Card numbers are encrypted and will be decrypted.
|
|
@@ -66,11 +58,11 @@ export declare function getAutofillEntries({ chromeDir, profile, browser, search
|
|
|
66
58
|
* @param options - Targeting options.
|
|
67
59
|
* @returns Array of credit card entries.
|
|
68
60
|
*/
|
|
69
|
-
export declare function getCreditCards({ chromeDir, profile, browser, decryptionKey }?: CreditCardOptions): CreditCardEntry[];
|
|
61
|
+
export declare function getCreditCards({ chromeDir, profilePath, profile, browser, decryptionKey, }?: CreditCardOptions): CreditCardEntry[];
|
|
70
62
|
/**
|
|
71
63
|
* Retrieves saved addresses from Chrome's Web Data database.
|
|
72
64
|
*
|
|
73
65
|
* @param options - Targeting options.
|
|
74
66
|
* @returns Array of address entries.
|
|
75
67
|
*/
|
|
76
|
-
export declare function getAddresses({ chromeDir, profile, browser }?: AddressOptions): AddressEntry[];
|
|
68
|
+
export declare function getAddresses({ chromeDir, profilePath, profile, browser }?: AddressOptions): AddressEntry[];
|
|
@@ -1 +1,170 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { resolveTargetProfiles } from "../core/chrome.js";
|
|
3
|
+
import { deriveEncryptionKey, decryptValue } from "../core/platform/index.js";
|
|
4
|
+
import { chromeTimeToDate } from "../core/crypto.js";
|
|
5
|
+
import { queryDatabase } from "../core/db.js";
|
|
6
|
+
import { limitResults, normalizeLimit } from "../core/limit.js";
|
|
7
|
+
import { sqlLikePattern } from "../core/sql.js";
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves autofill entries from Chrome's Web Data database.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Filtering and targeting options.
|
|
12
|
+
* @returns Array of autofill entries.
|
|
13
|
+
*/
|
|
14
|
+
export function getAutofillEntries({ chromeDir, profilePath, profile, browser, search, limit = 100, } = {}) {
|
|
15
|
+
const profiles = resolveTargetProfiles({ chromeDir, profilePath, profile, browser });
|
|
16
|
+
const results = [];
|
|
17
|
+
const rowLimit = normalizeLimit(limit);
|
|
18
|
+
for (const p of profiles) {
|
|
19
|
+
const dbPath = join(p.path, "Web Data");
|
|
20
|
+
try {
|
|
21
|
+
// Apply search in SQL before LIMIT so older matches are not truncated away.
|
|
22
|
+
let sql = `SELECT name, value, date_created, date_last_used, count FROM autofill`;
|
|
23
|
+
const params = [];
|
|
24
|
+
if (search) {
|
|
25
|
+
sql += ` WHERE IFNULL(name, '') LIKE ? ESCAPE '\\' OR IFNULL(value, '') LIKE ? ESCAPE '\\'`;
|
|
26
|
+
const like = sqlLikePattern(search);
|
|
27
|
+
params.push(like, like);
|
|
28
|
+
}
|
|
29
|
+
sql += ` ORDER BY date_last_used DESC`;
|
|
30
|
+
if (rowLimit) {
|
|
31
|
+
sql += ` LIMIT ${rowLimit}`;
|
|
32
|
+
}
|
|
33
|
+
const rows = queryDatabase(dbPath, sql, params);
|
|
34
|
+
for (const row of rows) {
|
|
35
|
+
results.push({
|
|
36
|
+
profile: p.name,
|
|
37
|
+
name: row.name || "",
|
|
38
|
+
value: row.value || "",
|
|
39
|
+
dateCreated: chromeTimeToDate(row.date_created ? BigInt(row.date_created) * 1000000n + 11644473600000000n : 0),
|
|
40
|
+
dateLastUsed: chromeTimeToDate(row.date_last_used ? BigInt(row.date_last_used) * 1000000n + 11644473600000000n : 0),
|
|
41
|
+
count: row.count || 0,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Skip profiles with errors
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return limitResults(results, limit);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves saved credit cards from Chrome's Web Data database.
|
|
53
|
+
* Card numbers are encrypted and will be decrypted.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Targeting options.
|
|
56
|
+
* @returns Array of credit card entries.
|
|
57
|
+
*/
|
|
58
|
+
export function getCreditCards({ chromeDir, profilePath, profile, browser, decryptionKey, } = {}) {
|
|
59
|
+
const userDataDir = profilePath || chromeDir;
|
|
60
|
+
const profiles = resolveTargetProfiles({ chromeDir, profilePath, profile, browser });
|
|
61
|
+
// Pass user-data dir so Windows reads Local State from the same tree as the profiles.
|
|
62
|
+
let derivedKey = decryptionKey;
|
|
63
|
+
const results = [];
|
|
64
|
+
for (const p of profiles) {
|
|
65
|
+
const dbPath = join(p.path, "Web Data");
|
|
66
|
+
try {
|
|
67
|
+
const rows = queryDatabase(dbPath, `SELECT guid, name_on_card, expiration_month, expiration_year,
|
|
68
|
+
card_number_encrypted, date_modified, origin, use_count,
|
|
69
|
+
nickname
|
|
70
|
+
FROM credit_cards ORDER BY use_date DESC`);
|
|
71
|
+
for (const row of rows) {
|
|
72
|
+
let cardNumber = "";
|
|
73
|
+
if (row.card_number_encrypted?.length > 0) {
|
|
74
|
+
cardNumber = decryptValue(row.card_number_encrypted, derivedKey ??= deriveEncryptionKey(userDataDir, browser));
|
|
75
|
+
}
|
|
76
|
+
results.push({
|
|
77
|
+
profile: p.name,
|
|
78
|
+
guid: row.guid || "",
|
|
79
|
+
nameOnCard: row.name_on_card || "",
|
|
80
|
+
expirationMonth: row.expiration_month || 0,
|
|
81
|
+
expirationYear: row.expiration_year || 0,
|
|
82
|
+
cardNumber,
|
|
83
|
+
nickname: row.nickname || "",
|
|
84
|
+
origin: row.origin || "",
|
|
85
|
+
useCount: row.use_count || 0,
|
|
86
|
+
dateModified: chromeTimeToDate(row.date_modified ? BigInt(row.date_modified) * 1000000n + 11644473600000000n : 0),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Skip profiles with errors
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Retrieves saved addresses from Chrome's Web Data database.
|
|
98
|
+
*
|
|
99
|
+
* @param options - Targeting options.
|
|
100
|
+
* @returns Array of address entries.
|
|
101
|
+
*/
|
|
102
|
+
export function getAddresses({ chromeDir, profilePath, profile, browser } = {}) {
|
|
103
|
+
const profiles = resolveTargetProfiles({ chromeDir, profilePath, profile, browser });
|
|
104
|
+
const results = [];
|
|
105
|
+
for (const p of profiles) {
|
|
106
|
+
const dbPath = join(p.path, "Web Data");
|
|
107
|
+
try {
|
|
108
|
+
const profileRows = queryDatabase(dbPath, `SELECT guid, company_name, street_address,
|
|
109
|
+
city, state, zipcode, country_code, date_modified,
|
|
110
|
+
origin, use_count
|
|
111
|
+
FROM autofill_profiles ORDER BY use_date DESC`);
|
|
112
|
+
// Try to join with names, emails, and phones
|
|
113
|
+
let nameRows = [];
|
|
114
|
+
let emailRows = [];
|
|
115
|
+
let phoneRows = [];
|
|
116
|
+
try {
|
|
117
|
+
nameRows = queryDatabase(dbPath, `SELECT guid, first_name, middle_name, last_name, full_name FROM autofill_profile_names`);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
/* ignore */
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
emailRows = queryDatabase(dbPath, `SELECT guid, email FROM autofill_profile_emails`);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
/* ignore */
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
phoneRows = queryDatabase(dbPath, `SELECT guid, number FROM autofill_profile_phones`);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
/* ignore */
|
|
133
|
+
}
|
|
134
|
+
const nameMap = new Map();
|
|
135
|
+
for (const n of nameRows) {
|
|
136
|
+
nameMap.set(n.guid, n.full_name || [n.first_name, n.middle_name, n.last_name].filter(Boolean).join(" "));
|
|
137
|
+
}
|
|
138
|
+
const emailMap = new Map();
|
|
139
|
+
for (const e of emailRows) {
|
|
140
|
+
emailMap.set(e.guid, e.email || "");
|
|
141
|
+
}
|
|
142
|
+
const phoneMap = new Map();
|
|
143
|
+
for (const ph of phoneRows) {
|
|
144
|
+
phoneMap.set(ph.guid, ph.number || "");
|
|
145
|
+
}
|
|
146
|
+
for (const row of profileRows) {
|
|
147
|
+
results.push({
|
|
148
|
+
profile: p.name,
|
|
149
|
+
guid: row.guid || "",
|
|
150
|
+
fullName: nameMap.get(row.guid) || "",
|
|
151
|
+
email: emailMap.get(row.guid) || "",
|
|
152
|
+
phone: phoneMap.get(row.guid) || "",
|
|
153
|
+
companyName: row.company_name || "",
|
|
154
|
+
streetAddress: row.street_address || "",
|
|
155
|
+
city: row.city || "",
|
|
156
|
+
state: row.state || "",
|
|
157
|
+
zipcode: row.zipcode || "",
|
|
158
|
+
countryCode: row.country_code || "",
|
|
159
|
+
origin: row.origin || "",
|
|
160
|
+
useCount: row.use_count || 0,
|
|
161
|
+
dateModified: chromeTimeToDate(row.date_modified ? BigInt(row.date_modified) * 1000000n + 11644473600000000n : 0),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Skip profiles with errors
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return results;
|
|
170
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
profile?: string;
|
|
4
|
-
browser?: string;
|
|
1
|
+
import { type ResolveProfilesOptions } from "../core/chrome.js";
|
|
2
|
+
export interface BookmarkOptions extends ResolveProfilesOptions {
|
|
5
3
|
folder?: string;
|
|
6
4
|
search?: string;
|
|
7
5
|
}
|
|
@@ -21,4 +19,4 @@ export interface BookmarkEntry {
|
|
|
21
19
|
* @param options - Options for filtering and targeting.
|
|
22
20
|
* @returns Filtered bookmark entries.
|
|
23
21
|
*/
|
|
24
|
-
export declare function getBookmarks({ chromeDir, profile, folder, search, browser }?: BookmarkOptions): BookmarkEntry[];
|
|
22
|
+
export declare function getBookmarks({ chromeDir, profilePath, profile, folder, search, browser, }?: BookmarkOptions): BookmarkEntry[];
|
|
@@ -1 +1,83 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resolveTargetProfiles } from "../core/chrome.js";
|
|
4
|
+
import { chromeTimeToDate } from "../core/crypto.js";
|
|
5
|
+
/**
|
|
6
|
+
* Recursively flattens the bookmark tree into a flat array.
|
|
7
|
+
*
|
|
8
|
+
* @param node - Bookmark tree node.
|
|
9
|
+
* @param folderPath - Current folder path for context.
|
|
10
|
+
* @returns Array of flattened bookmark entries.
|
|
11
|
+
*/
|
|
12
|
+
function flattenBookmarks(node, folderPath = "") {
|
|
13
|
+
const results = [];
|
|
14
|
+
if (!node)
|
|
15
|
+
return results;
|
|
16
|
+
const currentPath = folderPath
|
|
17
|
+
? `${folderPath}/${node.name || ""}`
|
|
18
|
+
: node.name || "";
|
|
19
|
+
if (node.type === "url") {
|
|
20
|
+
results.push({
|
|
21
|
+
title: node.name || "",
|
|
22
|
+
url: node.url || "",
|
|
23
|
+
folder: folderPath,
|
|
24
|
+
dateAdded: chromeTimeToDate(node.date_added),
|
|
25
|
+
dateLastUsed: chromeTimeToDate(node.date_last_used),
|
|
26
|
+
id: node.id,
|
|
27
|
+
guid: node.guid || "",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (node.children && Array.isArray(node.children)) {
|
|
31
|
+
for (const child of node.children) {
|
|
32
|
+
results.push(...flattenBookmarks(child, currentPath));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return results;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads and parses bookmarks from Chrome's Bookmarks JSON file.
|
|
39
|
+
*
|
|
40
|
+
* @param options - Options for filtering and targeting.
|
|
41
|
+
* @returns Filtered bookmark entries.
|
|
42
|
+
*/
|
|
43
|
+
export function getBookmarks({ chromeDir, profilePath, profile, folder, search, browser, } = {}) {
|
|
44
|
+
const profiles = resolveTargetProfiles({ chromeDir, profilePath, profile, browser });
|
|
45
|
+
const results = [];
|
|
46
|
+
for (const p of profiles) {
|
|
47
|
+
const bookmarksPath = join(p.path, "Bookmarks");
|
|
48
|
+
if (!existsSync(bookmarksPath))
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
const raw = readFileSync(bookmarksPath, "utf-8");
|
|
52
|
+
const data = JSON.parse(raw);
|
|
53
|
+
const roots = data.roots;
|
|
54
|
+
if (!roots)
|
|
55
|
+
continue;
|
|
56
|
+
// Flatten all root bookmark folders
|
|
57
|
+
const rootNames = ["bookmark_bar", "other", "synced"];
|
|
58
|
+
for (const rootName of rootNames) {
|
|
59
|
+
if (roots[rootName]) {
|
|
60
|
+
const bookmarks = flattenBookmarks(roots[rootName], "");
|
|
61
|
+
for (const bm of bookmarks) {
|
|
62
|
+
bm.profile = p.name;
|
|
63
|
+
results.push(bm);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Skip profiles with parse errors
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let filtered = results;
|
|
73
|
+
if (folder) {
|
|
74
|
+
const term = folder.toLowerCase();
|
|
75
|
+
filtered = filtered.filter((b) => b.folder.toLowerCase().includes(term));
|
|
76
|
+
}
|
|
77
|
+
if (search) {
|
|
78
|
+
const term = search.toLowerCase();
|
|
79
|
+
filtered = filtered.filter((b) => b.title.toLowerCase().includes(term) ||
|
|
80
|
+
b.url.toLowerCase().includes(term));
|
|
81
|
+
}
|
|
82
|
+
return filtered;
|
|
83
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
profile?: string;
|
|
4
|
-
browser?: string;
|
|
1
|
+
import { type ResolveProfilesOptions } from "../core/chrome.js";
|
|
2
|
+
export interface CookieOptions extends ResolveProfilesOptions {
|
|
5
3
|
domain?: string;
|
|
6
4
|
url?: string;
|
|
7
5
|
decrypt?: boolean;
|
|
@@ -32,7 +30,7 @@ declare function pathMatch(urlPath: string, cookiePath: string): boolean;
|
|
|
32
30
|
* @param options - Targeting and filtering options.
|
|
33
31
|
* @returns Array of cookie entries.
|
|
34
32
|
*/
|
|
35
|
-
export declare function getCookies({ chromeDir, profile, browser, domain, url, decrypt, limit, decryptionKey, }?: CookieOptions): CookieEntry[];
|
|
33
|
+
export declare function getCookies({ chromeDir, profilePath, profile, browser, domain, url, decrypt, limit, decryptionKey, }?: CookieOptions): CookieEntry[];
|
|
36
34
|
export declare const _test: {
|
|
37
35
|
parseURL: typeof parseURL;
|
|
38
36
|
getPossibleHostKeys: typeof getPossibleHostKeys;
|
|
@@ -1 +1,157 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { resolveTargetProfiles } from "../core/chrome.js";
|
|
4
|
+
import { deriveEncryptionKey, decryptValueBuffer } from "../core/platform/index.js";
|
|
5
|
+
import { chromeTimeToDate } from "../core/crypto.js";
|
|
6
|
+
import { queryDatabase } from "../core/db.js";
|
|
7
|
+
import { limitResults, normalizeLimit } from "../core/limit.js";
|
|
8
|
+
function decodeCookieValue(encryptedValue, derivedKey, hostKey) {
|
|
9
|
+
const decrypted = decryptValueBuffer(encryptedValue, derivedKey);
|
|
10
|
+
if (!Buffer.isBuffer(decrypted)) {
|
|
11
|
+
return decrypted;
|
|
12
|
+
}
|
|
13
|
+
const hostHash = createHash("sha256").update(hostKey).digest();
|
|
14
|
+
const valueBytes = decrypted.length >= hostHash.length && decrypted.subarray(0, hostHash.length).equals(hostHash)
|
|
15
|
+
? decrypted.subarray(hostHash.length)
|
|
16
|
+
: decrypted;
|
|
17
|
+
return valueBytes.toString("utf-8");
|
|
18
|
+
}
|
|
19
|
+
function parseURL(urlStr) {
|
|
20
|
+
if (!urlStr)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
return new URL(urlStr);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
try {
|
|
27
|
+
// If it doesn't have a protocol, prepend https://
|
|
28
|
+
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(urlStr)) {
|
|
29
|
+
return new URL("https://" + urlStr);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Ignore
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function getPossibleHostKeys(hostname) {
|
|
39
|
+
const keys = new Set();
|
|
40
|
+
keys.add(hostname);
|
|
41
|
+
keys.add("." + hostname);
|
|
42
|
+
const parts = hostname.split(".");
|
|
43
|
+
for (let i = 1; i < parts.length; i++) {
|
|
44
|
+
const suffix = parts.slice(i).join(".");
|
|
45
|
+
keys.add(suffix);
|
|
46
|
+
keys.add("." + suffix);
|
|
47
|
+
}
|
|
48
|
+
return Array.from(keys);
|
|
49
|
+
}
|
|
50
|
+
function domainMatch(hostname, hostKey) {
|
|
51
|
+
if (hostname === hostKey) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (hostKey.startsWith(".")) {
|
|
55
|
+
if (hostname === hostKey.slice(1) || hostname.endsWith(hostKey)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function pathMatch(urlPath, cookiePath) {
|
|
62
|
+
const uPath = urlPath || "/";
|
|
63
|
+
const cPath = cookiePath || "/";
|
|
64
|
+
if (cPath === "/") {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (uPath === cPath) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (uPath.startsWith(cPath)) {
|
|
71
|
+
if (cPath.endsWith("/") || uPath[cPath.length] === "/") {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Extracts cookies from Chrome's Cookies database.
|
|
79
|
+
* Encrypted values are decrypted using the same mechanism as passwords.
|
|
80
|
+
*
|
|
81
|
+
* @param options - Targeting and filtering options.
|
|
82
|
+
* @returns Array of cookie entries.
|
|
83
|
+
*/
|
|
84
|
+
export function getCookies({ chromeDir, profilePath, profile, browser, domain, url, decrypt = true, limit = 100, decryptionKey, } = {}) {
|
|
85
|
+
const userDataDir = profilePath || chromeDir;
|
|
86
|
+
const profiles = resolveTargetProfiles({ chromeDir, profilePath, profile, browser });
|
|
87
|
+
let derivedKey = decryptionKey;
|
|
88
|
+
const results = [];
|
|
89
|
+
const parsedUrl = parseURL(url);
|
|
90
|
+
const rowLimit = normalizeLimit(limit);
|
|
91
|
+
for (const p of profiles) {
|
|
92
|
+
const dbPath = join(p.path, "Cookies");
|
|
93
|
+
try {
|
|
94
|
+
let sql = `SELECT host_key, name, value, encrypted_value, path,
|
|
95
|
+
expires_utc, is_secure, is_httponly, samesite,
|
|
96
|
+
creation_utc, last_access_utc
|
|
97
|
+
FROM cookies`;
|
|
98
|
+
const conditions = [];
|
|
99
|
+
const params = [];
|
|
100
|
+
if (domain) {
|
|
101
|
+
conditions.push(`host_key LIKE ?`);
|
|
102
|
+
params.push(`%${domain}%`);
|
|
103
|
+
}
|
|
104
|
+
else if (parsedUrl) {
|
|
105
|
+
const hostKeys = getPossibleHostKeys(parsedUrl.hostname);
|
|
106
|
+
const placeholders = hostKeys.map(() => "?").join(", ");
|
|
107
|
+
conditions.push(`host_key IN (${placeholders})`);
|
|
108
|
+
params.push(...hostKeys);
|
|
109
|
+
}
|
|
110
|
+
if (conditions.length > 0) {
|
|
111
|
+
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
112
|
+
}
|
|
113
|
+
sql += ` ORDER BY host_key, name`;
|
|
114
|
+
if (rowLimit && !url) {
|
|
115
|
+
sql += ` LIMIT ${rowLimit}`;
|
|
116
|
+
}
|
|
117
|
+
const rows = queryDatabase(dbPath, sql, params);
|
|
118
|
+
for (const row of rows) {
|
|
119
|
+
if (parsedUrl) {
|
|
120
|
+
if (!domainMatch(parsedUrl.hostname, row.host_key || ""))
|
|
121
|
+
continue;
|
|
122
|
+
if (!pathMatch(parsedUrl.pathname || "/", row.path || "/"))
|
|
123
|
+
continue;
|
|
124
|
+
if (row.is_secure && parsedUrl.protocol !== "https:")
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
let cookieValue = row.value || "";
|
|
128
|
+
if (!cookieValue && row.encrypted_value?.length > 0 && decrypt) {
|
|
129
|
+
cookieValue = decodeCookieValue(row.encrypted_value, derivedKey ??= deriveEncryptionKey(userDataDir, browser), row.host_key || "");
|
|
130
|
+
}
|
|
131
|
+
results.push({
|
|
132
|
+
profile: p.name,
|
|
133
|
+
domain: row.host_key || "",
|
|
134
|
+
name: row.name || "",
|
|
135
|
+
value: cookieValue,
|
|
136
|
+
path: row.path || "/",
|
|
137
|
+
expires: chromeTimeToDate(row.expires_utc || 0),
|
|
138
|
+
secure: Boolean(row.is_secure),
|
|
139
|
+
httpOnly: Boolean(row.is_httponly),
|
|
140
|
+
sameSite: ["unspecified", "lax", "strict", "none"][row.samesite] || "unspecified",
|
|
141
|
+
created: chromeTimeToDate(row.creation_utc || 0),
|
|
142
|
+
lastAccessed: chromeTimeToDate(row.last_access_utc || 0),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// Skip profiles with errors
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return limitResults(results, limit);
|
|
151
|
+
}
|
|
152
|
+
export const _test = {
|
|
153
|
+
parseURL,
|
|
154
|
+
getPossibleHostKeys,
|
|
155
|
+
domainMatch,
|
|
156
|
+
pathMatch,
|
|
157
|
+
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
profile?: string;
|
|
4
|
-
browser?: string;
|
|
1
|
+
import { type ResolveProfilesOptions } from "../core/chrome.js";
|
|
2
|
+
export interface DownloadOptions extends ResolveProfilesOptions {
|
|
5
3
|
search?: string;
|
|
6
4
|
limit?: number;
|
|
7
5
|
}
|
|
@@ -26,4 +24,4 @@ export interface DownloadEntry {
|
|
|
26
24
|
* @param options - Targeting, filtering, and limit options.
|
|
27
25
|
* @returns Array of download entries.
|
|
28
26
|
*/
|
|
29
|
-
export declare function getDownloads({ chromeDir, profile, browser, search, limit, }?: DownloadOptions): DownloadEntry[];
|
|
27
|
+
export declare function getDownloads({ chromeDir, profilePath, profile, browser, search, limit, }?: DownloadOptions): DownloadEntry[];
|