camoufox-js 0.9.1 → 0.9.3
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/pkgman.js +44 -21
- package/package.json +7 -6
package/dist/pkgman.js
CHANGED
|
@@ -5,7 +5,8 @@ import * as path from "node:path";
|
|
|
5
5
|
import { setTimeout } from "node:timers/promises";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import AdmZip from "adm-zip";
|
|
8
|
-
import
|
|
8
|
+
import cliProgress from "cli-progress";
|
|
9
|
+
import prettyBytes from "pretty-bytes";
|
|
9
10
|
import { CONSTRAINTS } from "./__version__.js";
|
|
10
11
|
import { CamoufoxNotInstalled, FileNotFoundError, MissingRelease, UnsupportedArchitecture, UnsupportedOS, UnsupportedVersion, } from "./exceptions.js";
|
|
11
12
|
const ARCH_MAP = {
|
|
@@ -19,12 +20,23 @@ const OS_MAP = {
|
|
|
19
20
|
linux: "lin",
|
|
20
21
|
win32: "win",
|
|
21
22
|
};
|
|
23
|
+
function getAuthorizationHeaders(url) {
|
|
24
|
+
const githubToken = process.env.GITHUB_TOKEN;
|
|
25
|
+
if (!githubToken)
|
|
26
|
+
return {};
|
|
27
|
+
const host = new URL(url).hostname;
|
|
28
|
+
if (host === "api.github.com" || host === "github.com") {
|
|
29
|
+
return { Authorization: `Bearer ${githubToken}` };
|
|
30
|
+
}
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
22
33
|
if (!(process.platform in OS_MAP)) {
|
|
23
34
|
throw new UnsupportedOS(`OS ${process.platform} is not supported`);
|
|
24
35
|
}
|
|
25
36
|
export const OS_NAME = OS_MAP[process.platform];
|
|
26
37
|
const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
|
|
27
38
|
export const INSTALL_DIR = userCacheDir("camoufox");
|
|
39
|
+
const formatBytes = (v, _, type) => type === "total" || type === "value" ? prettyBytes(v) : String(v);
|
|
28
40
|
export const LOCAL_DATA = path.join(currentDir, "data-files");
|
|
29
41
|
export const OS_ARCH_MATRIX = {
|
|
30
42
|
win: ["x86_64", "i686"],
|
|
@@ -109,7 +121,9 @@ export class GitHubDownloader {
|
|
|
109
121
|
let response;
|
|
110
122
|
while (attempts < retries) {
|
|
111
123
|
try {
|
|
112
|
-
response = await fetch(this.apiUrl
|
|
124
|
+
response = await fetch(this.apiUrl, {
|
|
125
|
+
headers: getAuthorizationHeaders(this.apiUrl),
|
|
126
|
+
});
|
|
113
127
|
if (response.ok)
|
|
114
128
|
break;
|
|
115
129
|
}
|
|
@@ -178,7 +192,9 @@ export class CamoufoxFetcher extends GitHubDownloader {
|
|
|
178
192
|
this._url = releaseData[1];
|
|
179
193
|
}
|
|
180
194
|
static async downloadFile(url) {
|
|
181
|
-
const response = await fetch(url
|
|
195
|
+
const response = await fetch(url, {
|
|
196
|
+
headers: getAuthorizationHeaders(url),
|
|
197
|
+
});
|
|
182
198
|
return Buffer.from(await response.arrayBuffer());
|
|
183
199
|
}
|
|
184
200
|
async extractZip(zipFile) {
|
|
@@ -296,7 +312,7 @@ export async function webdl(url, desc = "", bar = true, buffer = null, { retries
|
|
|
296
312
|
let response;
|
|
297
313
|
while (attempts < retries) {
|
|
298
314
|
try {
|
|
299
|
-
response = await fetch(url);
|
|
315
|
+
response = await fetch(url, { headers: getAuthorizationHeaders(url) });
|
|
300
316
|
if (response.ok)
|
|
301
317
|
break;
|
|
302
318
|
}
|
|
@@ -310,26 +326,33 @@ export async function webdl(url, desc = "", bar = true, buffer = null, { retries
|
|
|
310
326
|
throw new Error(`Failed to download from ${url} after ${retries} attempts`);
|
|
311
327
|
}
|
|
312
328
|
const totalSize = parseInt(response.headers.get("content-length") || "0", 10);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
329
|
+
let progressBar = null;
|
|
330
|
+
if (bar && totalSize > 0) {
|
|
331
|
+
progressBar = new cliProgress.SingleBar({
|
|
332
|
+
format: `${desc} [{bar}] {percentage}% | ETA: {eta_formatted} | {value}/{total}`,
|
|
333
|
+
formatValue: formatBytes,
|
|
334
|
+
noTTYOutput: true,
|
|
335
|
+
}, cliProgress.Presets.shades_classic);
|
|
336
|
+
progressBar.start(totalSize, 0);
|
|
337
|
+
}
|
|
319
338
|
const chunks = [];
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
buffer
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
progressBar
|
|
339
|
+
try {
|
|
340
|
+
for await (const chunk of response.body) {
|
|
341
|
+
if (buffer) {
|
|
342
|
+
buffer.write(chunk);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
chunks.push(chunk);
|
|
346
|
+
}
|
|
347
|
+
if (progressBar) {
|
|
348
|
+
progressBar.increment(chunk.length);
|
|
349
|
+
}
|
|
329
350
|
}
|
|
330
351
|
}
|
|
331
|
-
|
|
332
|
-
|
|
352
|
+
finally {
|
|
353
|
+
progressBar?.stop();
|
|
354
|
+
}
|
|
355
|
+
return Buffer.concat(chunks);
|
|
333
356
|
}
|
|
334
357
|
export async function unzip(zipFile, extractPath, desc, bar = true) {
|
|
335
358
|
const zip = new AdmZip(zipFile);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "camoufox-js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -28,27 +28,28 @@
|
|
|
28
28
|
},
|
|
29
29
|
"license": "MPL-2.0",
|
|
30
30
|
"description": "Experimental JS port of Camoufox for Python.",
|
|
31
|
-
"packageManager": "yarn@4.
|
|
31
|
+
"packageManager": "yarn@4.13.0",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"adm-zip": "^0.5.16",
|
|
34
34
|
"better-sqlite3": "^12.2.0",
|
|
35
|
+
"cli-progress": "^3.12.0",
|
|
35
36
|
"commander": "^14.0.0",
|
|
36
37
|
"fingerprint-generator": "^2.1.66",
|
|
37
38
|
"glob": "^13.0.0",
|
|
38
|
-
"impit": "^0.
|
|
39
|
+
"impit": "^0.11.0",
|
|
39
40
|
"language-tags": "^2.0.1",
|
|
40
41
|
"maxmind": "^5.0.0",
|
|
41
|
-
"
|
|
42
|
+
"pretty-bytes": "^7.1.0",
|
|
42
43
|
"ua-parser-js": "^2.0.2",
|
|
43
44
|
"xml2js": "^0.6.2"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@biomejs/biome": "2.4.
|
|
47
|
+
"@biomejs/biome": "2.4.8",
|
|
47
48
|
"@types/adm-zip": "^0.5.7",
|
|
48
49
|
"@types/better-sqlite3": "^7.6.13",
|
|
50
|
+
"@types/cli-progress": "^3.11.6",
|
|
49
51
|
"@types/language-tags": "^1.0.4",
|
|
50
52
|
"@types/node": "^24.0.0",
|
|
51
|
-
"@types/progress": "^2.0.7",
|
|
52
53
|
"@types/xml2js": "^0.4.14",
|
|
53
54
|
"playwright-core": "^1.53.1",
|
|
54
55
|
"rimraf": "^6.0.1",
|