@procedures/browser 0.55.0 → 0.55.2
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/CHANGELOG.md +22 -0
- package/README.md +60 -1
- package/dist/bookmarks.d.ts +93 -0
- package/dist/bookmarks.d.ts.map +1 -0
- package/dist/bookmarks.js +139 -0
- package/dist/bookmarks.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/profiles.d.ts +70 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/profiles.js +121 -0
- package/dist/profiles.js.map +1 -0
- package/dist/run.d.ts +8 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +48 -22
- package/dist/run.js.map +1 -1
- package/dist/screenshot.d.ts +21 -0
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +18 -2
- package/dist/screenshot.js.map +1 -1
- package/package.json +15 -5
- package/src/bookmarks.ts +215 -0
- package/src/index.ts +3 -0
- package/src/profiles.ts +176 -0
- package/src/run.ts +47 -20
- package/src/screenshot.ts +34 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @procedures/browser
|
|
2
2
|
|
|
3
|
+
## 0.55.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a86b44f: `@procedures/browser` finds and reads the bookmarks files of the profiles of Chrome, Edge and Chromium, and gives a screenshot as bytes. The change adds names and is backward compatible, so it is a patch.
|
|
8
|
+
|
|
9
|
+
- `browserDataFolders(platform, env, home, browsers)` gives the folder of the user data of each browser on each platform.
|
|
10
|
+
- `findBookmarkFiles(folders, files)` finds the files `Bookmarks` and `AccountBookmarks` of each profile, with the names of the profiles.
|
|
11
|
+
- Each file has its browser and its size. Its id is `<browser>:<profile folder>:<file name>`, so the files of two browsers have different ids.
|
|
12
|
+
- `readBookmarkFile(file, files, options)` reads and parses a file. It refuses a file over `MAX_BOOKMARKS_BYTES` before the read.
|
|
13
|
+
- `parseChromeBookmarks(value, options)` reads the JSON of a bookmarks file. It gives the folders with their sites, and a problem for each part that it cannot read.
|
|
14
|
+
- The new entry `@procedures/browser/bookmarks` has the parser and its types, with no Node built-in. A page can use it.
|
|
15
|
+
- `renderScreenshotBytes(options)` gives the picture as a `Uint8Array`. It removes its temporary folder, also after an error.
|
|
16
|
+
- Each render removes its work folder through one helper. A removal that fails does not hide the result or the error of the render. Without `output`, the file is in its own temporary folder.
|
|
17
|
+
- @procedures/shell@0.55.2
|
|
18
|
+
|
|
19
|
+
## 0.55.1
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- @procedures/shell@0.55.1
|
|
24
|
+
|
|
3
25
|
## 0.55.0
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
npm install @procedures/browser
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
This package finds a Chromium browser that is already on the host: Microsoft Edge, Google Chrome or Chromium. It renders a page with that browser: a PDF file or a screenshot. The package does not download a browser.
|
|
9
|
+
This package finds a Chromium browser that is already on the host: Microsoft Edge, Google Chrome or Chromium. It renders a page with that browser: a PDF file or a screenshot. The package does not download a browser. It also finds and reads the bookmarks files of the profiles of Chrome, Edge and Chromium.
|
|
10
10
|
|
|
11
11
|
Each render uses one headless run. The run starts the browser one time, with argv, in a new temporary folder with its own profile. The renders give only their flags and the check of their file.
|
|
12
12
|
|
|
@@ -31,6 +31,19 @@ const { path, bytes, format } = await renderScreenshot({
|
|
|
31
31
|
- The option `budget` gives the scripts and the timers of the page more virtual time before the picture, in milliseconds. Without it, the picture follows the load event.
|
|
32
32
|
- The page can load each address that it names. Give an address that you trust, or a page of your own.
|
|
33
33
|
|
|
34
|
+
### A screenshot as bytes
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { renderScreenshotBytes } from "@procedures/browser";
|
|
38
|
+
|
|
39
|
+
const { data, format } = await renderScreenshotBytes({ url: "https://example.com/", format: "jpeg" });
|
|
40
|
+
const picture = `data:image/jpeg;base64,${Buffer.from(data).toString("base64")}`;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- `renderScreenshotBytes` has the options and the errors of `renderScreenshot`, with no `output`. It gives the picture as a `Uint8Array`.
|
|
44
|
+
- The function writes the picture to a new temporary folder, and reads it. Then it removes the folder, also after an error.
|
|
45
|
+
- The option `folder` sets the folder that gets the temporary folder. The default is the temporary folder of the system.
|
|
46
|
+
|
|
34
47
|
## A PDF file
|
|
35
48
|
|
|
36
49
|
```ts
|
|
@@ -57,6 +70,7 @@ const { path, bytes } = await renderPdf({ html: "<h1>Menu</h1><p>Soup of the day
|
|
|
57
70
|
- The temporary profile keeps the render apart from a browser that the user has open.
|
|
58
71
|
- A missing file, an empty file or a file of the wrong kind gives an error.
|
|
59
72
|
- An existing output file changes only after the check of the new file. Thus a failed render keeps an old output file.
|
|
73
|
+
- Each render removes its temporary page and profile, also after an error. For a file that Windows holds, the removal tries again 3 times.
|
|
60
74
|
|
|
61
75
|
## The browser
|
|
62
76
|
|
|
@@ -70,6 +84,49 @@ const { path, bytes } = await renderPdf({ html: "<h1>Menu</h1><p>Soup of the day
|
|
|
70
84
|
|
|
71
85
|
When the search finds no browser, each render gives an error that names `PDF_BROWSER`. The name comes from `@procedures/pdf`, the first home of the search.
|
|
72
86
|
|
|
87
|
+
## The bookmarks of the profiles
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { homedir } from "node:os";
|
|
91
|
+
import { browserDataFolders, findBookmarkFiles, readBookmarkFile } from "@procedures/browser";
|
|
92
|
+
|
|
93
|
+
const files = await findBookmarkFiles(browserDataFolders(process.platform, process.env, homedir()));
|
|
94
|
+
for (const file of files) console.log(file.id, file.browser, file.name, file.kind, file.size);
|
|
95
|
+
const first = files[0] === undefined ? undefined : await readBookmarkFile(files[0]);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- `browserDataFolders(platform, env, home, browsers)` gives the folder of the user data of each browser on Windows, macOS and Linux. It reads no file.
|
|
99
|
+
- The browsers are `chrome`, `edge` and `chromium` (`PROFILE_BROWSERS`), the browsers that `findBrowser` finds. The argument `browsers` selects some of them.
|
|
100
|
+
- `findBookmarkFiles(folders, files)` finds the files `Bookmarks` and `AccountBookmarks` of each profile. It reads the names of the profiles from the file `Local State`. Each folder has the key of its browser, so a caller can add the folder of another Chromium browser.
|
|
101
|
+
- The files come in the order of the folders. In a folder, `Default` comes first, then `Profile <n>` by the number. The guest and system profiles have no bookmarks.
|
|
102
|
+
- The id of a file is `<browser>:<profile folder>:<file name>`, for example `edge:Default:Bookmarks`. The files of two browsers have different ids. A host can give the id and the name to a page, and keep the path.
|
|
103
|
+
- Each file has its `path` and its `size` in bytes at the time of the search.
|
|
104
|
+
- `readBookmarkFile(file, files, options)` reads and parses a file. It reads the size again, and refuses a file over `MAX_BOOKMARKS_BYTES` before the read. The default prefix of the keys is the id of the file and a colon.
|
|
105
|
+
- The argument `files` is the file access. The default is `diskFileAccess`. A test gives files in memory.
|
|
106
|
+
- `diskFileAccess.list` gives no names for each error: a missing folder, and also a folder that it cannot read (`EACCES`).
|
|
107
|
+
|
|
108
|
+
`parseChromeBookmarks(value, options)` reads the JSON of a bookmarks file. Chrome, Edge and Chromium write the same format. The parser gives the root folders, each with its folders and its sites.
|
|
109
|
+
|
|
110
|
+
- Each site has its address, its title, the time when the user added it, and the names of its folders as `path`.
|
|
111
|
+
- The parser keeps only the `http` and `https` addresses. The count `skipped` tells how many other bookmarks the file has.
|
|
112
|
+
- A part that the parser cannot read gives a problem in `problems`. The parser reads the other parts.
|
|
113
|
+
- The key of a folder is its `guid`, else its `id`, else its place in the file. The place is the name of its root and the index of each child. Thus each folder of a file has a different key.
|
|
114
|
+
- The option `prefix` goes before each key of a folder. Give two files different prefixes, so that their keys are different.
|
|
115
|
+
- The roots of Chrome come first. The roots with other names come after them, in the order of their code units. Thus each runtime gives the same parse.
|
|
116
|
+
- The parser reads 100 folders deep at most (`MAX_BOOKMARK_DEPTH`). A deeper folder gives a problem.
|
|
117
|
+
- A value with no object `roots` is not a bookmarks file. Then the parser throws.
|
|
118
|
+
- `MAX_BOOKMARKS_BYTES` is the largest bookmarks file: 64 MB. `readBookmarkFile` applies it. A page that reads a file of its own examines the size before the read.
|
|
119
|
+
|
|
120
|
+
### The entry for a page
|
|
121
|
+
|
|
122
|
+
The entry `@procedures/browser/bookmarks` imports no Node built-in, so a page can use it. It has the parser and its types, not the search.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { parseChromeBookmarks, type ChromeBookmarks } from "@procedures/browser/bookmarks";
|
|
126
|
+
|
|
127
|
+
const read: ChromeBookmarks = parseChromeBookmarks(JSON.parse(await chosenFile.text()), { prefix: "file:1:" });
|
|
128
|
+
```
|
|
129
|
+
|
|
73
130
|
## The other functions
|
|
74
131
|
|
|
75
132
|
- `browserCandidates(platform, env)` gives the paths that the search examines.
|
|
@@ -78,3 +135,5 @@ When the search finds no browser, each render gives an error that names `PDF_BRO
|
|
|
78
135
|
- `screenshotFormatOf(output, format)` gives the format of a screenshot.
|
|
79
136
|
- `isPdfFile(path)` tells if a file starts with `%PDF`.
|
|
80
137
|
- `isImageFile(path, format)` tells if a file starts with the signature of a PNG, JPEG or WebP file.
|
|
138
|
+
- `chromeTime(value)` gives the ISO 8601 time of a Chrome time: a text of the microseconds from 1601-01-01.
|
|
139
|
+
- `profileNames(localState)` gives the name of each profile from the JSON of the file `Local State`.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bookmarks files of Chrome. Edge and Chromium write the same format. This file reads the JSON
|
|
3
|
+
* of a bookmarks file, and gives a tree of folders with their sites. It also reads the names of the
|
|
4
|
+
* profiles from the file `Local State`.
|
|
5
|
+
*
|
|
6
|
+
* This file imports no Node built-in, so a page can use it: the entry `@procedures/browser/bookmarks`.
|
|
7
|
+
* The search for the files on the disk is in `profiles.ts`, on the root entry.
|
|
8
|
+
*/
|
|
9
|
+
/** The deepest folder that the parser reads. A deeper folder gives a problem, and the parser does not read it. */
|
|
10
|
+
export declare const MAX_BOOKMARK_DEPTH = 100;
|
|
11
|
+
/** The largest bookmarks file that a reader accepts, in bytes. A larger file is not a bookmarks file. */
|
|
12
|
+
export declare const MAX_BOOKMARKS_BYTES: number;
|
|
13
|
+
/**
|
|
14
|
+
* The kind of a bookmarks file. `profile` is the file `Bookmarks` of a profile. `account` is the
|
|
15
|
+
* file `AccountBookmarks`: the bookmarks of a Google account with no sync.
|
|
16
|
+
*/
|
|
17
|
+
export type BookmarkFileKind = "profile" | "account";
|
|
18
|
+
/** The bookmarks files of a profile, by the name of the file, with their kinds. */
|
|
19
|
+
export declare const BOOKMARK_FILES: Readonly<Record<string, BookmarkFileKind>>;
|
|
20
|
+
/** A bookmarks file, with no path. A host can give this to a page and keep the path. */
|
|
21
|
+
export interface BookmarkSource {
|
|
22
|
+
/** The id of the file. The search gives `<browser>:<profile folder>:<file name>`, for example `chrome:Default:Bookmarks`. */
|
|
23
|
+
readonly id: string;
|
|
24
|
+
/** The name of the profile, as the browser shows it. */
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly kind: BookmarkFileKind;
|
|
27
|
+
}
|
|
28
|
+
/** A bookmark of a web site. */
|
|
29
|
+
export interface Bookmark {
|
|
30
|
+
/** The address of the site: an `http` or `https` address with a host. */
|
|
31
|
+
readonly url: string;
|
|
32
|
+
/** The title of the bookmark. A bookmark with an empty title has no title. */
|
|
33
|
+
readonly title?: string;
|
|
34
|
+
/** The ISO 8601 time when the user added the bookmark. */
|
|
35
|
+
readonly added?: string;
|
|
36
|
+
/** The names of the folders from the root to the folder of the bookmark. */
|
|
37
|
+
readonly path: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
/** A folder of the bookmarks, with its sites and the folders in it. */
|
|
40
|
+
export interface BookmarkFolder {
|
|
41
|
+
/**
|
|
42
|
+
* The key of the folder, after the prefix of the parse: its `guid`, else its `id`, else its place in the file. The place is
|
|
43
|
+
* the name of the root, then the index of each child, for example `bookmark_bar/2/0`. Each parse of a file gives the same keys.
|
|
44
|
+
*/
|
|
45
|
+
readonly key: string;
|
|
46
|
+
readonly name: string;
|
|
47
|
+
/** The names of the folders from the root to this folder. The last name is the name of this folder. */
|
|
48
|
+
readonly path: readonly string[];
|
|
49
|
+
readonly folders: readonly BookmarkFolder[];
|
|
50
|
+
/** The sites directly in this folder. Each site has the path of this folder. */
|
|
51
|
+
readonly sites: readonly Bookmark[];
|
|
52
|
+
/** The count of the sites in this folder and in each folder in it. */
|
|
53
|
+
readonly total: number;
|
|
54
|
+
}
|
|
55
|
+
/** A part of a bookmarks file that the parser cannot read. */
|
|
56
|
+
export interface BookmarkProblem {
|
|
57
|
+
/** The names of the folders to the part. */
|
|
58
|
+
readonly path: readonly string[];
|
|
59
|
+
readonly message: string;
|
|
60
|
+
}
|
|
61
|
+
/** The result of the parse of a bookmarks file. */
|
|
62
|
+
export interface ChromeBookmarks {
|
|
63
|
+
/** The root folders, for example "Bookmarks bar" and "Other bookmarks". */
|
|
64
|
+
readonly roots: readonly BookmarkFolder[];
|
|
65
|
+
/** The count of the bookmarks that are not web sites, for example `javascript:` or `chrome://` addresses. */
|
|
66
|
+
readonly skipped: number;
|
|
67
|
+
readonly problems: readonly BookmarkProblem[];
|
|
68
|
+
}
|
|
69
|
+
/** The options of `parseChromeBookmarks`. */
|
|
70
|
+
export interface ParseChromeBookmarksOptions {
|
|
71
|
+
/** The text before each key. Give two files of one profile different prefixes, so that their keys are different. */
|
|
72
|
+
readonly prefix?: string | undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* This function gives the ISO 8601 time of a Chrome time, or `undefined` for no time. A Chrome time
|
|
76
|
+
* is a text of the microseconds from 1601-01-01 UTC. The function uses `BigInt`, because the value
|
|
77
|
+
* is larger than a safe integer.
|
|
78
|
+
*/
|
|
79
|
+
export declare function chromeTime(value: unknown): string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* This function reads the JSON value of a Chrome bookmarks file: the file `Bookmarks` or
|
|
82
|
+
* `AccountBookmarks` of a profile. It gives a problem for each part that it cannot read, and it
|
|
83
|
+
* reads the other parts. It keeps only the bookmarks of web sites, and counts the others.
|
|
84
|
+
*
|
|
85
|
+
* @throws Error when the value has no roots, so it is not a bookmarks file
|
|
86
|
+
*/
|
|
87
|
+
export declare function parseChromeBookmarks(value: unknown, options?: ParseChromeBookmarksOptions): ChromeBookmarks;
|
|
88
|
+
/**
|
|
89
|
+
* This function gives the name of each profile from the JSON of the file `Local State` of a
|
|
90
|
+
* Chromium browser, by the folder of the profile. A value that it cannot read gives no names.
|
|
91
|
+
*/
|
|
92
|
+
export declare function profileNames(localState: unknown): Map<string, string>;
|
|
93
|
+
//# sourceMappingURL=bookmarks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bookmarks.d.ts","sourceRoot":"","sources":["../src/bookmarks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,kHAAkH;AAClH,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,yGAAyG;AACzG,eAAO,MAAM,mBAAmB,EAAE,MAAyB,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAAC;AAErD,mFAAmF;AACnF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAyD,CAAC;AAEhI,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,6HAA6H;IAC7H,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACjC;AAED,gCAAgC;AAChC,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AAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAM7D;AA6BD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,2BAAgC,GAAG,eAAe,CAuD/G;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CASrE"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bookmarks files of Chrome. Edge and Chromium write the same format. This file reads the JSON
|
|
3
|
+
* of a bookmarks file, and gives a tree of folders with their sites. It also reads the names of the
|
|
4
|
+
* profiles from the file `Local State`.
|
|
5
|
+
*
|
|
6
|
+
* This file imports no Node built-in, so a page can use it: the entry `@procedures/browser/bookmarks`.
|
|
7
|
+
* The search for the files on the disk is in `profiles.ts`, on the root entry.
|
|
8
|
+
*/
|
|
9
|
+
/** The deepest folder that the parser reads. A deeper folder gives a problem, and the parser does not read it. */
|
|
10
|
+
export const MAX_BOOKMARK_DEPTH = 100;
|
|
11
|
+
/** The largest bookmarks file that a reader accepts, in bytes. A larger file is not a bookmarks file. */
|
|
12
|
+
export const MAX_BOOKMARKS_BYTES = 64 * 1024 * 1024;
|
|
13
|
+
/** The bookmarks files of a profile, by the name of the file, with their kinds. */
|
|
14
|
+
export const BOOKMARK_FILES = { Bookmarks: "profile", AccountBookmarks: "account" };
|
|
15
|
+
/** The order of the roots that Chrome writes. The roots with other names come after them, in the order of their code units. */
|
|
16
|
+
const ROOT_ORDER = ["bookmark_bar", "other", "synced"];
|
|
17
|
+
/** The time from 1601-01-01 (the start of the Chrome times) to 1970-01-01, in milliseconds. */
|
|
18
|
+
const WINDOWS_EPOCH_MS = 11644473600000n;
|
|
19
|
+
/**
|
|
20
|
+
* A web address has the scheme `http` or `https`, a host, and no spaces. The test does not use `URL`, so it is the same in each
|
|
21
|
+
* runtime. The first character of the host is one class, and the rest is `\S*`. Thus no two quantifiers agree on the same
|
|
22
|
+
* character, and the time of the test is linear in the length of the address.
|
|
23
|
+
*/
|
|
24
|
+
const WEB = /^https?:\/\/[^\s/?#]\S*$/i;
|
|
25
|
+
/**
|
|
26
|
+
* This function gives the ISO 8601 time of a Chrome time, or `undefined` for no time. A Chrome time
|
|
27
|
+
* is a text of the microseconds from 1601-01-01 UTC. The function uses `BigInt`, because the value
|
|
28
|
+
* is larger than a safe integer.
|
|
29
|
+
*/
|
|
30
|
+
export function chromeTime(value) {
|
|
31
|
+
if (typeof value !== "string" || !/^\d{1,20}$/.test(value))
|
|
32
|
+
return undefined;
|
|
33
|
+
const ms = BigInt(value) / 1000n - WINDOWS_EPOCH_MS;
|
|
34
|
+
// The time 0 means no time. A time before 1990 or after 9999 is not a date of a bookmark.
|
|
35
|
+
if (ms < 631152000000n || ms > 253402300799999n)
|
|
36
|
+
return undefined;
|
|
37
|
+
return new Date(Number(ms)).toISOString();
|
|
38
|
+
}
|
|
39
|
+
function isNode(value) {
|
|
40
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41
|
+
}
|
|
42
|
+
/** This function gives the `guid` of a folder, else its `id`. An empty text or a value of another type is not a key. */
|
|
43
|
+
function ownKey(node) {
|
|
44
|
+
if (typeof node.guid === "string" && node.guid !== "")
|
|
45
|
+
return node.guid;
|
|
46
|
+
if (typeof node.id === "string" && node.id !== "")
|
|
47
|
+
return node.id;
|
|
48
|
+
if (typeof node.id === "number" && Number.isFinite(node.id))
|
|
49
|
+
return String(node.id);
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
function rank(name) {
|
|
53
|
+
const index = ROOT_ORDER.indexOf(name);
|
|
54
|
+
return index === -1 ? ROOT_ORDER.length : index;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* This function reads the JSON value of a Chrome bookmarks file: the file `Bookmarks` or
|
|
58
|
+
* `AccountBookmarks` of a profile. It gives a problem for each part that it cannot read, and it
|
|
59
|
+
* reads the other parts. It keeps only the bookmarks of web sites, and counts the others.
|
|
60
|
+
*
|
|
61
|
+
* @throws Error when the value has no roots, so it is not a bookmarks file
|
|
62
|
+
*/
|
|
63
|
+
export function parseChromeBookmarks(value, options = {}) {
|
|
64
|
+
const prefix = options.prefix ?? "";
|
|
65
|
+
if (!isNode(value) || !isNode(value.roots))
|
|
66
|
+
throw new Error("A Chrome bookmarks file has an object roots.");
|
|
67
|
+
const rootNodes = value.roots;
|
|
68
|
+
const problems = [];
|
|
69
|
+
let skipped = 0;
|
|
70
|
+
// The place of a folder is the name of its root, then the index of each child to it. It is unique in a file.
|
|
71
|
+
const folderOf = (node, parent, fallback, depth, place) => {
|
|
72
|
+
const name = typeof node.name === "string" && node.name !== "" ? node.name : fallback;
|
|
73
|
+
const path = [...parent, name];
|
|
74
|
+
const own = ownKey(node) ?? place;
|
|
75
|
+
const folders = [];
|
|
76
|
+
const sites = [];
|
|
77
|
+
let total = 0;
|
|
78
|
+
const children = Array.isArray(node.children) ? node.children : [];
|
|
79
|
+
if (node.children !== undefined && !Array.isArray(node.children))
|
|
80
|
+
problems.push({ path, message: "The children of a folder must be a list." });
|
|
81
|
+
for (const [index, child] of children.entries()) {
|
|
82
|
+
if (!isNode(child)) {
|
|
83
|
+
problems.push({ path, message: "A bookmark must be an object." });
|
|
84
|
+
}
|
|
85
|
+
else if (child.type === "url") {
|
|
86
|
+
if (typeof child.url !== "string" || !WEB.test(child.url)) {
|
|
87
|
+
skipped++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const title = typeof child.name === "string" && child.name.trim() !== "" ? child.name : undefined;
|
|
91
|
+
const added = chromeTime(child.date_added);
|
|
92
|
+
sites.push({ url: child.url, ...(title === undefined ? {} : { title }), ...(added === undefined ? {} : { added }), path });
|
|
93
|
+
total++;
|
|
94
|
+
}
|
|
95
|
+
else if (child.type === "folder") {
|
|
96
|
+
if (depth >= MAX_BOOKMARK_DEPTH) {
|
|
97
|
+
problems.push({ path, message: `A folder is deeper than ${MAX_BOOKMARK_DEPTH} folders. The parser does not read it.` });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const folder = folderOf(child, path, "Folder", depth + 1, `${place}/${index}`);
|
|
101
|
+
folders.push(folder);
|
|
102
|
+
total += folder.total;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
problems.push({ path, message: `A bookmark has the type ${String(child.type)}, not url or folder.` });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { key: `${prefix}${own}`, name, path, folders, sites, total };
|
|
109
|
+
};
|
|
110
|
+
// The order of the code units, not of a locale, so each runtime gives the same parse. The names are the keys of one
|
|
111
|
+
// object, so no two names are equal.
|
|
112
|
+
const names = Object.keys(rootNodes).sort((a, b) => rank(a) - rank(b) || (a < b ? -1 : 1));
|
|
113
|
+
const roots = [];
|
|
114
|
+
for (const name of names) {
|
|
115
|
+
const node = rootNodes[name];
|
|
116
|
+
// The roots object of an old file also has values that are not folders, for example a sync transaction version
|
|
117
|
+
if (!isNode(node) || node.type !== "folder")
|
|
118
|
+
continue;
|
|
119
|
+
roots.push(folderOf(node, [], name, 1, name));
|
|
120
|
+
}
|
|
121
|
+
return { roots, skipped, problems };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* This function gives the name of each profile from the JSON of the file `Local State` of a
|
|
125
|
+
* Chromium browser, by the folder of the profile. A value that it cannot read gives no names.
|
|
126
|
+
*/
|
|
127
|
+
export function profileNames(localState) {
|
|
128
|
+
const names = new Map();
|
|
129
|
+
const cache = localState?.profile?.info_cache;
|
|
130
|
+
if (typeof cache !== "object" || cache === null)
|
|
131
|
+
return names;
|
|
132
|
+
for (const [folder, info] of Object.entries(cache)) {
|
|
133
|
+
const name = info?.name;
|
|
134
|
+
if (typeof name === "string" && name.trim() !== "")
|
|
135
|
+
names.set(folder, name);
|
|
136
|
+
}
|
|
137
|
+
return names;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMapp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AAkC,EAAE,IAAI,CAAC;QACvD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export * from "./browser.js";
|
|
|
2
2
|
export { DEFAULT_TIMEOUT_MS, type CommandRunner, type HeadlessOptions, type RenderResult } from "./run.js";
|
|
3
3
|
export { isPdfFile, pdfArgs, renderPdf, type RenderPdfOptions, type RenderPdfResult } from "./pdf.js";
|
|
4
4
|
export * from "./screenshot.js";
|
|
5
|
+
export * from "./bookmarks.js";
|
|
6
|
+
export * from "./profiles.js";
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AACtG,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,UAAU,CAAC;AACtG,cAAc,iBAAiB,CAAC;AAEhC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,7 @@ export * from "./browser.js";
|
|
|
3
3
|
export { DEFAULT_TIMEOUT_MS } from "./run.js";
|
|
4
4
|
export { isPdfFile, pdfArgs, renderPdf } from "./pdf.js";
|
|
5
5
|
export * from "./screenshot.js";
|
|
6
|
+
// The bookmarks files of Chrome, Edge and Chromium: the parse (also on the browser entry ./bookmarks) and the search on the disk
|
|
7
|
+
export * from "./bookmarks.js";
|
|
8
|
+
export * from "./profiles.js";
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAA+D,MAAM,UAAU,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAA+C,MAAM,UAAU,CAAC;AACtG,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAA+D,MAAM,UAAU,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAA+C,MAAM,UAAU,CAAC;AACtG,cAAc,iBAAiB,CAAC;AAChC,iIAAiI;AACjI,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The profiles of the Chromium browsers on the disk: Google Chrome, Microsoft Edge and Chromium.
|
|
3
|
+
* This file finds the folders of the user data of each browser. Then it finds the bookmarks files of
|
|
4
|
+
* each profile in them, with the names of the profiles, and reads a file. The parse is in `bookmarks.ts`.
|
|
5
|
+
* This file uses Node.js, so only the root entry exports it.
|
|
6
|
+
*/
|
|
7
|
+
import { type BookmarkSource, type ChromeBookmarks, type ParseChromeBookmarksOptions } from "./bookmarks.js";
|
|
8
|
+
/** The file operations of the search and of the read. A test gives files in memory. */
|
|
9
|
+
export interface FileAccess {
|
|
10
|
+
/** This function gives the names in a folder, or no names when the folder does not exist. */
|
|
11
|
+
list(folder: string): Promise<readonly string[]>;
|
|
12
|
+
/** This function gives the size of a file in bytes, or `undefined` when the file does not exist. */
|
|
13
|
+
size(file: string): Promise<number | undefined>;
|
|
14
|
+
/** This function gives the text of a file in UTF-8. */
|
|
15
|
+
read(file: string): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The file operations on the disk. `list` gives no names for each error, not only for a missing
|
|
19
|
+
* folder: also for a folder that it cannot read (`EACCES`). `size` gives `undefined` for each error
|
|
20
|
+
* and for a path that is not a file. `read` throws the error of the disk.
|
|
21
|
+
*/
|
|
22
|
+
export declare const diskFileAccess: FileAccess;
|
|
23
|
+
/**
|
|
24
|
+
* The key of a Chromium browser that keeps its profiles in a folder of user data. These are the
|
|
25
|
+
* browsers that `findBrowser` finds. The key is the first part of the id of a bookmarks file.
|
|
26
|
+
*/
|
|
27
|
+
export type ProfileBrowser = "chrome" | "edge" | "chromium";
|
|
28
|
+
/** The browsers of `browserDataFolders`, in the order of its result. */
|
|
29
|
+
export declare const PROFILE_BROWSERS: readonly ProfileBrowser[];
|
|
30
|
+
/** A folder of the user data of a browser. Each profile of the browser is a folder in it. */
|
|
31
|
+
export interface BrowserDataFolder {
|
|
32
|
+
/** The key of the browser, for example `chrome`. Another key, for example `brave`, is also correct. */
|
|
33
|
+
readonly browser: string;
|
|
34
|
+
/** The path of the folder. */
|
|
35
|
+
readonly folder: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* This function gives the folders of the user data of the browsers for a platform. Windows uses
|
|
39
|
+
* `LOCALAPPDATA`, macOS uses `~/Library/Application Support`, and Linux uses `XDG_CONFIG_HOME` or `~/.config`.
|
|
40
|
+
* The function reads no file, so a folder in the result can be absent.
|
|
41
|
+
*/
|
|
42
|
+
export declare function browserDataFolders(platform: NodeJS.Platform, env: Readonly<Record<string, string | undefined>>, home: string, browsers?: readonly ProfileBrowser[]): BrowserDataFolder[];
|
|
43
|
+
/** A bookmarks file that the search found, with its browser, its profile folder and its path. */
|
|
44
|
+
export interface BookmarkFile extends BookmarkSource {
|
|
45
|
+
/** The key of the browser of the profile, for example `chrome` or `edge`. */
|
|
46
|
+
readonly browser: string;
|
|
47
|
+
/** The name of the folder of the profile, for example `Default` or `Profile 2`. */
|
|
48
|
+
readonly profile: string;
|
|
49
|
+
/** The path of the file. */
|
|
50
|
+
readonly path: string;
|
|
51
|
+
/** The size of the file in bytes, at the time of the search. A file over `MAX_BOOKMARKS_BYTES` is not a bookmarks file. */
|
|
52
|
+
readonly size: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* This function finds the bookmarks files of the profiles in the folders of the user data, in the
|
|
56
|
+
* order of the folders. In a folder, it gives `Default` first, then `Profile <n>` by the number. The
|
|
57
|
+
* file `Local State` gives the names of the profiles. Without it, a profile has the name of its folder.
|
|
58
|
+
* The id of a file starts with the key of its browser, so the files of two browsers have different ids.
|
|
59
|
+
*/
|
|
60
|
+
export declare function findBookmarkFiles(folders: readonly BrowserDataFolder[], files?: FileAccess): Promise<BookmarkFile[]>;
|
|
61
|
+
/**
|
|
62
|
+
* This function reads and parses a bookmarks file that `findBookmarkFiles` found. It reads the size
|
|
63
|
+
* again, because the file can change after the search. It refuses a file over `MAX_BOOKMARKS_BYTES`
|
|
64
|
+
* before the read. The default prefix of the keys is the id of the file and a colon, so the keys of
|
|
65
|
+
* two files are different.
|
|
66
|
+
*
|
|
67
|
+
* @throws Error when the file is not there, is too large, is not JSON or has no roots
|
|
68
|
+
*/
|
|
69
|
+
export declare function readBookmarkFile(file: Pick<BookmarkFile, "id" | "path">, files?: FileAccess, options?: ParseChromeBookmarksOptions): Promise<ChromeBookmarks>;
|
|
70
|
+
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,2BAA2B,EACjC,MAAM,gBAAgB,CAAC;AAExB,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACzB,6FAA6F;IAC7F,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IACjD,oGAAoG;IACpG,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAChD,uDAAuD;IACvD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,UAiB5B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5D,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,EAAE,SAAS,cAAc,EAAmC,CAAC;AAE1F,6FAA6F;AAC7F,MAAM,WAAW,iBAAiB;IAChC,uGAAuG;IACvG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AASD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACjD,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,SAAS,cAAc,EAAqB,GACrD,iBAAiB,EAAE,CAWrB;AAWD,iGAAiG;AACjG,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2HAA2H;IAC3H,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,EAAE,KAAK,GAAE,UAA2B,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAoB1I;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,MAAM,CAAC,EACvC,KAAK,GAAE,UAA2B,EAClC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,eAAe,CAAC,CAc1B"}
|
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The profiles of the Chromium browsers on the disk: Google Chrome, Microsoft Edge and Chromium.
|
|
3
|
+
* This file finds the folders of the user data of each browser. Then it finds the bookmarks files of
|
|
4
|
+
* each profile in them, with the names of the profiles, and reads a file. The parse is in `bookmarks.ts`.
|
|
5
|
+
* This file uses Node.js, so only the root entry exports it.
|
|
6
|
+
*/
|
|
7
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
8
|
+
import { join, posix, win32 } from "node:path";
|
|
9
|
+
import { BOOKMARK_FILES, MAX_BOOKMARKS_BYTES, parseChromeBookmarks, profileNames, } from "./bookmarks.js";
|
|
10
|
+
/**
|
|
11
|
+
* The file operations on the disk. `list` gives no names for each error, not only for a missing
|
|
12
|
+
* folder: also for a folder that it cannot read (`EACCES`). `size` gives `undefined` for each error
|
|
13
|
+
* and for a path that is not a file. `read` throws the error of the disk.
|
|
14
|
+
*/
|
|
15
|
+
export const diskFileAccess = {
|
|
16
|
+
list: async (folder) => {
|
|
17
|
+
try {
|
|
18
|
+
return await readdir(folder);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
size: async (file) => {
|
|
25
|
+
try {
|
|
26
|
+
const found = await stat(file);
|
|
27
|
+
return found.isFile() ? found.size : undefined;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
read: (file) => readFile(file, "utf8"),
|
|
34
|
+
};
|
|
35
|
+
/** The browsers of `browserDataFolders`, in the order of its result. */
|
|
36
|
+
export const PROFILE_BROWSERS = ["chrome", "edge", "chromium"];
|
|
37
|
+
/** The parts of the path of the user data of each browser, on each platform. */
|
|
38
|
+
const DATA_PATHS = {
|
|
39
|
+
chrome: { windows: ["Google", "Chrome", "User Data"], mac: ["Google", "Chrome"], linux: "google-chrome" },
|
|
40
|
+
edge: { windows: ["Microsoft", "Edge", "User Data"], mac: ["Microsoft Edge"], linux: "microsoft-edge" },
|
|
41
|
+
chromium: { windows: ["Chromium", "User Data"], mac: ["Chromium"], linux: "chromium" },
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* This function gives the folders of the user data of the browsers for a platform. Windows uses
|
|
45
|
+
* `LOCALAPPDATA`, macOS uses `~/Library/Application Support`, and Linux uses `XDG_CONFIG_HOME` or `~/.config`.
|
|
46
|
+
* The function reads no file, so a folder in the result can be absent.
|
|
47
|
+
*/
|
|
48
|
+
export function browserDataFolders(platform, env, home, browsers = PROFILE_BROWSERS) {
|
|
49
|
+
if (platform === "win32") {
|
|
50
|
+
const local = env["LOCALAPPDATA"] ?? win32.join(home, "AppData", "Local");
|
|
51
|
+
return browsers.map((browser) => ({ browser, folder: win32.join(local, ...DATA_PATHS[browser].windows) }));
|
|
52
|
+
}
|
|
53
|
+
if (platform === "darwin") {
|
|
54
|
+
const support = posix.join(home, "Library", "Application Support");
|
|
55
|
+
return browsers.map((browser) => ({ browser, folder: posix.join(support, ...DATA_PATHS[browser].mac) }));
|
|
56
|
+
}
|
|
57
|
+
const config = env["XDG_CONFIG_HOME"] ?? posix.join(home, ".config");
|
|
58
|
+
return browsers.map((browser) => ({ browser, folder: posix.join(config, DATA_PATHS[browser].linux) }));
|
|
59
|
+
}
|
|
60
|
+
/** A profile folder has the name `Default` or `Profile <n>`. The guest and system profiles have no bookmarks. */
|
|
61
|
+
const PROFILE = /^(Default|Profile \d+)$/;
|
|
62
|
+
/** This function gives the order of two profile folders: `Default` first, then `Profile <n>` by the number. */
|
|
63
|
+
function profileOrder(a, b) {
|
|
64
|
+
const number = (name) => (name === "Default" ? 0 : Number(name.slice("Profile ".length)));
|
|
65
|
+
return number(a) - number(b);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* This function finds the bookmarks files of the profiles in the folders of the user data, in the
|
|
69
|
+
* order of the folders. In a folder, it gives `Default` first, then `Profile <n>` by the number. The
|
|
70
|
+
* file `Local State` gives the names of the profiles. Without it, a profile has the name of its folder.
|
|
71
|
+
* The id of a file starts with the key of its browser, so the files of two browsers have different ids.
|
|
72
|
+
*/
|
|
73
|
+
export async function findBookmarkFiles(folders, files = diskFileAccess) {
|
|
74
|
+
const found = [];
|
|
75
|
+
for (const { browser, folder } of folders) {
|
|
76
|
+
let names = new Map();
|
|
77
|
+
try {
|
|
78
|
+
names = profileNames(JSON.parse(await files.read(join(folder, "Local State"))));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// A missing or broken file Local State gives the names of the folders
|
|
82
|
+
}
|
|
83
|
+
const profiles = new Set([...names.keys(), ...(await files.list(folder))].filter((name) => PROFILE.test(name)));
|
|
84
|
+
for (const profile of [...profiles].sort(profileOrder)) {
|
|
85
|
+
for (const [file, kind] of Object.entries(BOOKMARK_FILES)) {
|
|
86
|
+
const path = join(folder, profile, file);
|
|
87
|
+
const size = await files.size(path);
|
|
88
|
+
if (size === undefined)
|
|
89
|
+
continue;
|
|
90
|
+
found.push({ id: `${browser}:${profile}:${file}`, name: names.get(profile) ?? profile, kind, browser, profile, path, size });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* This function reads and parses a bookmarks file that `findBookmarkFiles` found. It reads the size
|
|
98
|
+
* again, because the file can change after the search. It refuses a file over `MAX_BOOKMARKS_BYTES`
|
|
99
|
+
* before the read. The default prefix of the keys is the id of the file and a colon, so the keys of
|
|
100
|
+
* two files are different.
|
|
101
|
+
*
|
|
102
|
+
* @throws Error when the file is not there, is too large, is not JSON or has no roots
|
|
103
|
+
*/
|
|
104
|
+
export async function readBookmarkFile(file, files = diskFileAccess, options = {}) {
|
|
105
|
+
const size = await files.size(file.path);
|
|
106
|
+
if (size === undefined)
|
|
107
|
+
throw new Error(`The file ${file.path} is not there now.`);
|
|
108
|
+
if (size > MAX_BOOKMARKS_BYTES) {
|
|
109
|
+
throw new Error(`The file ${file.path} has ${size} bytes. A bookmarks file has ${MAX_BOOKMARKS_BYTES} bytes at most.`);
|
|
110
|
+
}
|
|
111
|
+
const text = await files.read(file.path);
|
|
112
|
+
let value;
|
|
113
|
+
try {
|
|
114
|
+
value = JSON.parse(text);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw new Error(`The file ${file.path} is not JSON, so it is not a bookmarks file.`, { cause: error });
|
|
118
|
+
}
|
|
119
|
+
return parseChromeBookmarks(value, { prefix: options.prefix ?? `${file.id}:` });
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot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AAY,IAAI,CAAC,IAAI,QAAQ,IAAI,gCAAgC,mBAAmB,iBAAiB,CAAC,CAAC;IACzH,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,IAAI,8CAA8C,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,oBAAoB,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;AAClF,CAAC"}
|
package/dist/run.d.ts
CHANGED
|
@@ -57,13 +57,20 @@ export interface HeadlessRender {
|
|
|
57
57
|
}
|
|
58
58
|
/** This function gives the first bytes of a file, at most `count` bytes. */
|
|
59
59
|
export declare function readHead(path: string, count: number): Buffer;
|
|
60
|
+
/**
|
|
61
|
+
* This function makes a new temporary folder, gives its path to `use`, and then removes the folder,
|
|
62
|
+
* also when `use` throws. The name of the folder starts with `prefix`. The folder is in `folder`,
|
|
63
|
+
* else in the temporary folder of the system. Each temporary folder of this package uses this function.
|
|
64
|
+
*/
|
|
65
|
+
export declare function withTemporaryFolder<T>(prefix: string, folder: string | undefined, use: (path: string) => Promise<T>): Promise<T>;
|
|
60
66
|
/**
|
|
61
67
|
* This function starts the browser one time for a render, and gives the path and the size of the
|
|
62
68
|
* file. It throws when it finds no browser, at the time limit and after a cancel. It also throws
|
|
63
69
|
* when the file is missing, empty or not of the kind of the render.
|
|
64
70
|
*
|
|
65
71
|
* An existing output file changes only after the check of the new file. Thus a failed render keeps
|
|
66
|
-
* an old output file.
|
|
72
|
+
* an old output file. Without the option `output`, the file goes in a new temporary folder. This
|
|
73
|
+
* folder stays after a success, and goes after a failure.
|
|
67
74
|
*/
|
|
68
75
|
export declare function headlessRender(render: HeadlessRender, source: PageSource, options: HeadlessOptions): Promise<RenderResult>;
|
|
69
76
|
//# sourceMappingURL=run.d.ts.map
|