camoufox-js 0.9.0 → 0.9.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/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 ProgressBar from "progress";
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 = {
@@ -25,6 +26,7 @@ if (!(process.platform in OS_MAP)) {
25
26
  export const OS_NAME = OS_MAP[process.platform];
26
27
  const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
27
28
  export const INSTALL_DIR = userCacheDir("camoufox");
29
+ const formatBytes = (v, _, type) => type === "total" || type === "value" ? prettyBytes(v) : String(v);
28
30
  export const LOCAL_DATA = path.join(currentDir, "data-files");
29
31
  export const OS_ARCH_MATRIX = {
30
32
  win: ["x86_64", "i686"],
@@ -310,26 +312,33 @@ export async function webdl(url, desc = "", bar = true, buffer = null, { retries
310
312
  throw new Error(`Failed to download from ${url} after ${retries} attempts`);
311
313
  }
312
314
  const totalSize = parseInt(response.headers.get("content-length") || "0", 10);
313
- const progressBar = bar
314
- ? new ProgressBar(`${desc} [:bar] :percent :etas`, {
315
- total: totalSize,
316
- width: 40,
317
- })
318
- : null;
315
+ let progressBar = null;
316
+ if (bar && totalSize > 0) {
317
+ progressBar = new cliProgress.SingleBar({
318
+ format: `${desc} [{bar}] {percentage}% | ETA: {eta_formatted} | {value}/{total}`,
319
+ formatValue: formatBytes,
320
+ noTTYOutput: true,
321
+ }, cliProgress.Presets.shades_classic);
322
+ progressBar.start(totalSize, 0);
323
+ }
319
324
  const chunks = [];
320
- for await (const chunk of response.body) {
321
- if (buffer) {
322
- buffer.write(chunk);
323
- }
324
- else {
325
- chunks.push(chunk);
326
- }
327
- if (progressBar) {
328
- progressBar.tick(chunk.length, "X");
325
+ try {
326
+ for await (const chunk of response.body) {
327
+ if (buffer) {
328
+ buffer.write(chunk);
329
+ }
330
+ else {
331
+ chunks.push(chunk);
332
+ }
333
+ if (progressBar) {
334
+ progressBar.increment(chunk.length);
335
+ }
329
336
  }
330
337
  }
331
- const fileBuffer = Buffer.concat(chunks);
332
- return fileBuffer;
338
+ finally {
339
+ progressBar?.stop();
340
+ }
341
+ return Buffer.concat(chunks);
333
342
  }
334
343
  export async function unzip(zipFile, extractPath, desc, bar = true) {
335
344
  const zip = new AdmZip(zipFile);
package/dist/server.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { firefox } from "playwright-core";
2
2
  import { launchOptions } from "./utils.js";
3
3
  export async function launchServer({ port, ws_path, ...options }) {
4
+ // Extract and normalize headless (virtual is treated as true for server mode)
5
+ const { headless, ...restOptions } = options;
6
+ const normalizedHeadless = headless === "virtual" ? true : headless;
4
7
  return firefox.launchServer({
5
- ...(await launchOptions(options)),
8
+ ...(await launchOptions({ ...restOptions, headless: normalizedHeadless })),
6
9
  port,
7
10
  wsPath: ws_path,
8
11
  });
@@ -1,7 +1,6 @@
1
1
  import { type Browser, type BrowserContext, type BrowserType } from "playwright-core";
2
2
  import { type LaunchOptions } from "./utils.js";
3
- export declare function Camoufox<UserDataDir extends string | undefined = undefined, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(launch_options?: LaunchOptions | {
4
- headless?: boolean | "virtual";
5
- user_data_dir: UserDataDir;
3
+ export declare function Camoufox<UserDataDir extends string | undefined = undefined, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(launch_options?: LaunchOptions & {
4
+ user_data_dir?: UserDataDir;
6
5
  }): Promise<ReturnType>;
7
6
  export declare function NewBrowser<UserDataDir extends string | false = false, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(playwright: BrowserType<Browser>, headless?: boolean | "virtual", fromOptions?: Record<string, any>, userDataDir?: UserDataDir, debug?: boolean, launch_options?: LaunchOptions): Promise<ReturnType>;
package/dist/sync_api.js CHANGED
@@ -7,16 +7,18 @@ export async function Camoufox(launch_options = {}) {
7
7
  }
8
8
  export async function NewBrowser(playwright, headless = false, fromOptions = {}, userDataDir = false, debug = false, launch_options = {}) {
9
9
  let virtualDisplay = null;
10
+ // Normalize headless to boolean and prepare options for launchOptions function
11
+ const normalizedHeadless = headless === "virtual" ? false : headless || false;
10
12
  if (headless === "virtual") {
11
13
  virtualDisplay = new VirtualDisplay(debug);
12
14
  launch_options.virtual_display = virtualDisplay.get();
13
- launch_options.headless = false;
14
- }
15
- else {
16
- launch_options.headless ||= headless;
17
15
  }
18
16
  if (!fromOptions || Object.keys(fromOptions).length === 0) {
19
- fromOptions = await launchOptions({ debug, ...launch_options });
17
+ fromOptions = await launchOptions({
18
+ debug,
19
+ ...launch_options,
20
+ headless: normalizedHeadless,
21
+ });
20
22
  }
21
23
  if (typeof userDataDir === "string") {
22
24
  const context = await playwright.launchPersistentContext(userDataDir, fromOptions);
package/dist/utils.d.ts CHANGED
@@ -55,8 +55,9 @@ export interface LaunchOptions {
55
55
  */
56
56
  ff_version?: number;
57
57
  /** Whether to run the browser in headless mode. Defaults to `false`.
58
+ * Can be `true`, `false`, or `"virtual"` to use a virtual display.
58
59
  */
59
- headless?: boolean;
60
+ headless?: boolean | "virtual";
60
61
  /** Whether to enable running scripts in the main world.
61
62
  * To use this, prepend "mw:" to the script: `page.evaluate("mw:" + script)`.
62
63
  */
@@ -84,5 +85,14 @@ export interface LaunchOptions {
84
85
  /** Additional Firefox launch options. */
85
86
  [key: string]: any;
86
87
  }
87
- export declare function launchOptions({ config, os, block_images, block_webrtc, block_webgl, disable_coop, webgl_config, geoip, humanize, locale, addons, fonts, custom_fonts_only, exclude_addons, screen, window, fingerprint, ff_version, headless, main_world_eval, executable_path, firefox_user_prefs, proxy, enable_cache, args, env, i_know_what_im_doing, debug, virtual_display, ...launch_options }: LaunchOptions): Promise<Record<string, any>>;
88
+ /**
89
+ * Prepare launch options for Playwright's Firefox browser.
90
+ *
91
+ * Note: This function only accepts `boolean` for the `headless` parameter.
92
+ * Callers must normalize `"virtual"` to `boolean` before calling this function.
93
+ * The virtual display setup is handled separately in the calling function.
94
+ */
95
+ export declare function launchOptions({ config, os, block_images, block_webrtc, block_webgl, disable_coop, webgl_config, geoip, humanize, locale, addons, fonts, custom_fonts_only, exclude_addons, screen, window, fingerprint, ff_version, headless, main_world_eval, executable_path, firefox_user_prefs, proxy, enable_cache, args, env, i_know_what_im_doing, debug, virtual_display, ...launch_options }: Omit<LaunchOptions, "headless"> & {
96
+ headless?: boolean;
97
+ }): Promise<Record<string, any>>;
88
98
  export {};
package/dist/utils.js CHANGED
@@ -276,15 +276,20 @@ function getProxyUrl(proxy) {
276
276
  url.password = password;
277
277
  return url;
278
278
  }
279
+ /**
280
+ * Prepare launch options for Playwright's Firefox browser.
281
+ *
282
+ * Note: This function only accepts `boolean` for the `headless` parameter.
283
+ * Callers must normalize `"virtual"` to `boolean` before calling this function.
284
+ * The virtual display setup is handled separately in the calling function.
285
+ */
279
286
  export async function launchOptions({ config, os, block_images, block_webrtc, block_webgl, disable_coop, webgl_config, geoip, humanize, locale, addons, fonts, custom_fonts_only, exclude_addons, screen, window, fingerprint, ff_version, headless, main_world_eval, executable_path, firefox_user_prefs, proxy, enable_cache, args, env, i_know_what_im_doing, debug, virtual_display, ...launch_options }) {
280
287
  // Build the config
281
288
  if (!config) {
282
289
  config = {};
283
290
  }
284
291
  // Set default values for optional arguments
285
- if (headless === undefined) {
286
- headless = false;
287
- }
292
+ const headlessBoolean = headless ?? false;
288
293
  if (!addons) {
289
294
  addons = [];
290
295
  }
@@ -339,7 +344,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
339
344
  // Generate a fingerprint
340
345
  if (!fingerprint) {
341
346
  fingerprint = generateFingerprint(window, {
342
- screen: screen || getScreenCons(headless || "DISPLAY" in env),
347
+ screen: screen || getScreenCons(headlessBoolean || "DISPLAY" in env),
343
348
  operatingSystems,
344
349
  });
345
350
  }
@@ -493,7 +498,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
493
498
  bypass: typeof proxy === "string" ? undefined : proxy?.bypass,
494
499
  }
495
500
  : undefined,
496
- headless: headless,
501
+ headless: headlessBoolean,
497
502
  ...launch_options,
498
503
  };
499
504
  return out;
@@ -11,7 +11,7 @@ let DatabaseConstructor = null;
11
11
  async function openDatabase(pathName) {
12
12
  if (!DatabaseConstructor) {
13
13
  if (typeof Bun !== "undefined") {
14
- // @ts-ignore - bun:sqlite only exists in Bun runtime
14
+ // @ts-expect-error - bun:sqlite only exists in Bun runtime
15
15
  const { Database: BunDatabase } = await import("bun:sqlite");
16
16
  DatabaseConstructor = BunDatabase;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camoufox-js",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -32,23 +32,24 @@
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.9.0",
39
+ "impit": "^0.11.0",
39
40
  "language-tags": "^2.0.1",
40
41
  "maxmind": "^5.0.0",
41
- "progress": "^2.0.3",
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.0",
47
+ "@biomejs/biome": "2.4.7",
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",