chrome-tools 1.1.15 → 1.1.16

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.
Files changed (57) hide show
  1. package/dist/cli.js +8602 -0
  2. package/dist/index.d.ts +629 -0
  3. package/dist/index.js +2297 -0
  4. package/package.json +62 -29
  5. package/dist/bin/chrome_abe_decrypt.exe +0 -0
  6. package/dist/bin/cli.d.ts +0 -9
  7. package/dist/bin/cli.js +0 -590
  8. package/dist/src/core/browsers.d.ts +0 -73
  9. package/dist/src/core/browsers.js +0 -186
  10. package/dist/src/core/chrome.d.ts +0 -124
  11. package/dist/src/core/chrome.js +0 -259
  12. package/dist/src/core/crypto.d.ts +0 -52
  13. package/dist/src/core/crypto.js +0 -152
  14. package/dist/src/core/db.d.ts +0 -22
  15. package/dist/src/core/db.js +0 -227
  16. package/dist/src/core/keychain.d.ts +0 -57
  17. package/dist/src/core/keychain.js +0 -191
  18. package/dist/src/core/limit.d.ts +0 -4
  19. package/dist/src/core/limit.js +0 -12
  20. package/dist/src/core/platform/darwin.d.ts +0 -12
  21. package/dist/src/core/platform/darwin.js +0 -31
  22. package/dist/src/core/platform/index.d.ts +0 -30
  23. package/dist/src/core/platform/index.js +0 -69
  24. package/dist/src/core/platform/linux.d.ts +0 -10
  25. package/dist/src/core/platform/linux.js +0 -64
  26. package/dist/src/core/platform/types.d.ts +0 -45
  27. package/dist/src/core/platform/types.js +0 -1
  28. package/dist/src/core/platform/win32.d.ts +0 -13
  29. package/dist/src/core/platform/win32.js +0 -329
  30. package/dist/src/core/sql.d.ts +0 -2
  31. package/dist/src/core/sql.js +0 -4
  32. package/dist/src/index.d.ts +0 -28
  33. package/dist/src/index.js +0 -34
  34. package/dist/src/modules/autofill.d.ts +0 -68
  35. package/dist/src/modules/autofill.js +0 -170
  36. package/dist/src/modules/bookmarks.d.ts +0 -22
  37. package/dist/src/modules/bookmarks.js +0 -83
  38. package/dist/src/modules/cookies.d.ts +0 -40
  39. package/dist/src/modules/cookies.js +0 -163
  40. package/dist/src/modules/downloads.d.ts +0 -27
  41. package/dist/src/modules/downloads.js +0 -80
  42. package/dist/src/modules/extensions.d.ts +0 -24
  43. package/dist/src/modules/extensions.js +0 -71
  44. package/dist/src/modules/history.d.ts +0 -34
  45. package/dist/src/modules/history.js +0 -83
  46. package/dist/src/modules/local-storage.d.ts +0 -40
  47. package/dist/src/modules/local-storage.js +0 -455
  48. package/dist/src/modules/passwords.d.ts +0 -50
  49. package/dist/src/modules/passwords.js +0 -198
  50. package/dist/src/modules/search-engines.d.ts +0 -21
  51. package/dist/src/modules/search-engines.js +0 -38
  52. package/dist/src/modules/top-sites.d.ts +0 -17
  53. package/dist/src/modules/top-sites.js +0 -33
  54. package/src/native/build.bat +0 -31
  55. package/src/native/chrome_abe_decrypt.c +0 -336
  56. package/src/native/chrome_abe_decrypt.exe +0 -0
  57. /package/{bin → dist}/chrome_abe_decrypt.exe +0 -0
package/dist/src/index.js DELETED
@@ -1,34 +0,0 @@
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,68 +0,0 @@
1
- import { type ResolveProfilesOptions } from "../core/chrome.js";
2
- export interface AutofillOptions extends ResolveProfilesOptions {
3
- search?: string;
4
- limit?: number;
5
- }
6
- export interface AutofillEntry {
7
- profile: string;
8
- name: string;
9
- value: string;
10
- dateCreated: string;
11
- dateLastUsed: string;
12
- count: number;
13
- }
14
- export interface CreditCardOptions extends ResolveProfilesOptions {
15
- decryptionKey?: Buffer;
16
- }
17
- export interface CreditCardEntry {
18
- profile: string;
19
- guid: string;
20
- nameOnCard: string;
21
- expirationMonth: number;
22
- expirationYear: number;
23
- cardNumber: string;
24
- nickname: string;
25
- origin: string;
26
- useCount: number;
27
- dateModified: string;
28
- }
29
- export interface AddressOptions extends ResolveProfilesOptions {
30
- }
31
- export interface AddressEntry {
32
- profile: string;
33
- guid: string;
34
- fullName: string;
35
- email: string;
36
- phone: string;
37
- companyName: string;
38
- streetAddress: string;
39
- city: string;
40
- state: string;
41
- zipcode: string;
42
- countryCode: string;
43
- origin: string;
44
- useCount: number;
45
- dateModified: string;
46
- }
47
- /**
48
- * Retrieves autofill entries from Chrome's Web Data database.
49
- *
50
- * @param options - Filtering and targeting options.
51
- * @returns Array of autofill entries.
52
- */
53
- export declare function getAutofillEntries({ chromeDir, profilePath, profile, browser, search, limit, }?: AutofillOptions): AutofillEntry[];
54
- /**
55
- * Retrieves saved credit cards from Chrome's Web Data database.
56
- * Card numbers are encrypted and will be decrypted.
57
- *
58
- * @param options - Targeting options.
59
- * @returns Array of credit card entries.
60
- */
61
- export declare function getCreditCards({ chromeDir, profilePath, profile, browser, decryptionKey, }?: CreditCardOptions): CreditCardEntry[];
62
- /**
63
- * Retrieves saved addresses from Chrome's Web Data database.
64
- *
65
- * @param options - Targeting options.
66
- * @returns Array of address entries.
67
- */
68
- export declare function getAddresses({ chromeDir, profilePath, profile, browser }?: AddressOptions): AddressEntry[];
@@ -1,170 +0,0 @@
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,22 +0,0 @@
1
- import { type ResolveProfilesOptions } from "../core/chrome.js";
2
- export interface BookmarkOptions extends ResolveProfilesOptions {
3
- folder?: string;
4
- search?: string;
5
- }
6
- export interface BookmarkEntry {
7
- profile?: string;
8
- title: string;
9
- url: string;
10
- folder: string;
11
- dateAdded: string;
12
- dateLastUsed: string;
13
- id?: string;
14
- guid?: string;
15
- }
16
- /**
17
- * Reads and parses bookmarks from Chrome's Bookmarks JSON file.
18
- *
19
- * @param options - Options for filtering and targeting.
20
- * @returns Filtered bookmark entries.
21
- */
22
- export declare function getBookmarks({ chromeDir, profilePath, profile, folder, search, browser, }?: BookmarkOptions): BookmarkEntry[];
@@ -1,83 +0,0 @@
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,40 +0,0 @@
1
- import { type ResolveProfilesOptions } from "../core/chrome.js";
2
- export interface CookieOptions extends ResolveProfilesOptions {
3
- domain?: string;
4
- url?: string;
5
- decrypt?: boolean;
6
- limit?: number;
7
- decryptionKey?: Buffer;
8
- }
9
- export interface CookieEntry {
10
- profile: string;
11
- domain: string;
12
- name: string;
13
- value: string;
14
- path: string;
15
- expires: string;
16
- secure: boolean;
17
- httpOnly: boolean;
18
- sameSite: string;
19
- created: string;
20
- lastAccessed: string;
21
- }
22
- declare function parseURL(urlStr?: string): URL | null;
23
- declare function getPossibleHostKeys(hostname: string): string[];
24
- declare function domainMatch(hostname: string, hostKey: string): boolean;
25
- declare function pathMatch(urlPath: string, cookiePath: string): boolean;
26
- /**
27
- * Extracts cookies from Chrome's Cookies database.
28
- * Encrypted values are decrypted using the same mechanism as passwords.
29
- *
30
- * @param options - Targeting and filtering options.
31
- * @returns Array of cookie entries.
32
- */
33
- export declare function getCookies({ chromeDir, profilePath, profile, browser, domain, url, decrypt, limit, decryptionKey, }?: CookieOptions): CookieEntry[];
34
- export declare const _test: {
35
- parseURL: typeof parseURL;
36
- getPossibleHostKeys: typeof getPossibleHostKeys;
37
- domainMatch: typeof domainMatch;
38
- pathMatch: typeof pathMatch;
39
- };
40
- export {};
@@ -1,163 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { createHash } from "node:crypto";
3
- import { resolveCookiesDatabasePath, 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
- let firstReadError;
92
- for (const p of profiles) {
93
- const dbPath = resolveCookiesDatabasePath(p.path);
94
- if (!existsSync(dbPath))
95
- continue;
96
- try {
97
- let sql = `SELECT host_key, name, value, encrypted_value, path,
98
- expires_utc, is_secure, is_httponly, samesite,
99
- creation_utc, last_access_utc
100
- FROM cookies`;
101
- const conditions = [];
102
- const params = [];
103
- if (domain) {
104
- conditions.push(`host_key LIKE ?`);
105
- params.push(`%${domain}%`);
106
- }
107
- else if (parsedUrl) {
108
- const hostKeys = getPossibleHostKeys(parsedUrl.hostname);
109
- const placeholders = hostKeys.map(() => "?").join(", ");
110
- conditions.push(`host_key IN (${placeholders})`);
111
- params.push(...hostKeys);
112
- }
113
- if (conditions.length > 0) {
114
- sql += ` WHERE ${conditions.join(" AND ")}`;
115
- }
116
- sql += ` ORDER BY host_key, name`;
117
- if (rowLimit && !url) {
118
- sql += ` LIMIT ${rowLimit}`;
119
- }
120
- const rows = queryDatabase(dbPath, sql, params);
121
- for (const row of rows) {
122
- if (parsedUrl) {
123
- if (!domainMatch(parsedUrl.hostname, row.host_key || ""))
124
- continue;
125
- if (!pathMatch(parsedUrl.pathname || "/", row.path || "/"))
126
- continue;
127
- if (row.is_secure && parsedUrl.protocol !== "https:")
128
- continue;
129
- }
130
- let cookieValue = row.value || "";
131
- if (!cookieValue && row.encrypted_value?.length > 0 && decrypt) {
132
- cookieValue = decodeCookieValue(row.encrypted_value, derivedKey ??= deriveEncryptionKey(userDataDir, browser), row.host_key || "");
133
- }
134
- results.push({
135
- profile: p.name,
136
- domain: row.host_key || "",
137
- name: row.name || "",
138
- value: cookieValue,
139
- path: row.path || "/",
140
- expires: chromeTimeToDate(row.expires_utc || 0),
141
- secure: Boolean(row.is_secure),
142
- httpOnly: Boolean(row.is_httponly),
143
- sameSite: ["unspecified", "lax", "strict", "none"][row.samesite] || "unspecified",
144
- created: chromeTimeToDate(row.creation_utc || 0),
145
- lastAccessed: chromeTimeToDate(row.last_access_utc || 0),
146
- });
147
- }
148
- }
149
- catch (error) {
150
- firstReadError ??= new Error(`Could not read cookies for profile "${p.name}" at ${dbPath}: ` +
151
- (error instanceof Error ? error.message : String(error)));
152
- }
153
- }
154
- if (results.length === 0 && firstReadError)
155
- throw firstReadError;
156
- return limitResults(results, limit);
157
- }
158
- export const _test = {
159
- parseURL,
160
- getPossibleHostKeys,
161
- domainMatch,
162
- pathMatch,
163
- };
@@ -1,27 +0,0 @@
1
- import { type ResolveProfilesOptions } from "../core/chrome.js";
2
- export interface DownloadOptions extends ResolveProfilesOptions {
3
- search?: string;
4
- limit?: number;
5
- }
6
- export interface DownloadEntry {
7
- profile: string;
8
- targetPath: string;
9
- url: string;
10
- siteUrl: string;
11
- referrer: string;
12
- totalBytes: number;
13
- receivedBytes: number;
14
- mimeType: string;
15
- state: string;
16
- dangerType: string;
17
- opened: boolean;
18
- startTime: string;
19
- endTime: string;
20
- }
21
- /**
22
- * Retrieves download history from Chrome's History database.
23
- *
24
- * @param options - Targeting, filtering, and limit options.
25
- * @returns Array of download entries.
26
- */
27
- export declare function getDownloads({ chromeDir, profilePath, profile, browser, search, limit, }?: DownloadOptions): DownloadEntry[];