camoufox-js 0.8.5 → 0.9.1

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/addons.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const DefaultAddons: {
5
5
  UBO: string;
6
6
  };
7
7
  export declare function confirmPaths(paths: string[]): void;
8
- export declare function addDefaultAddons(_addonsList: string[], _excludeList?: (keyof typeof DefaultAddons)[]): void;
8
+ export declare function addDefaultAddons(addonsList: string[], excludeList?: (keyof typeof DefaultAddons)[]): Promise<void>;
9
9
  /**
10
10
  * Downloads and extracts an addon from a given URL to a specified path
11
11
  */
@@ -14,4 +14,4 @@ export declare function downloadAndExtract(url: string, extractPath: string, nam
14
14
  * Downloads and extracts addons from a given dictionary to a specified list
15
15
  * Skips downloading if the addon is already downloaded
16
16
  */
17
- export declare function maybeDownloadAddons(addons: Record<string, string>, addonsList?: string[]): void;
17
+ export declare function maybeDownloadAddons(addons: Record<string, string>, addonsList?: string[]): Promise<void>;
package/dist/addons.js CHANGED
@@ -22,20 +22,24 @@ export function confirmPaths(paths) {
22
22
  }
23
23
  }
24
24
  }
25
- export function addDefaultAddons(_addonsList, _excludeList = []) {
26
- // TODO - enable addons
25
+ export async function addDefaultAddons(addonsList, excludeList = []) {
27
26
  /**
28
27
  * Adds default addons, minus any specified in excludeList, to addonsList
29
28
  */
30
- // const addons = Object.values(DefaultAddons).filter(addon => !excludeList.includes(addon as keyof typeof DefaultAddons));
31
- // maybeDownloadAddons(addons, addonsList);
29
+ const addons = {};
30
+ for (const [name, url] of Object.entries(DefaultAddons)) {
31
+ if (!excludeList.includes(name)) {
32
+ addons[name] = url;
33
+ }
34
+ }
35
+ await maybeDownloadAddons(addons, addonsList);
32
36
  }
33
37
  /**
34
38
  * Downloads and extracts an addon from a given URL to a specified path
35
39
  */
36
40
  export async function downloadAndExtract(url, extractPath, name) {
37
41
  const buffer = await webdl(url, `Downloading addon (${name})`, false);
38
- unzip(buffer, extractPath, `Extracting addon (${name})`, false);
42
+ await unzip(buffer, extractPath, `Extracting addon (${name})`, false);
39
43
  }
40
44
  /**
41
45
  * Returns a path to the addon
@@ -47,7 +51,7 @@ function getAddonPath(addonName) {
47
51
  * Downloads and extracts addons from a given dictionary to a specified list
48
52
  * Skips downloading if the addon is already downloaded
49
53
  */
50
- export function maybeDownloadAddons(addons, addonsList = []) {
54
+ export async function maybeDownloadAddons(addons, addonsList = []) {
51
55
  if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
52
56
  console.log("Skipping addon download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
53
57
  return;
@@ -60,7 +64,7 @@ export function maybeDownloadAddons(addons, addonsList = []) {
60
64
  }
61
65
  try {
62
66
  fs.mkdirSync(addonPath, { recursive: true });
63
- downloadAndExtract(addons[addonName], addonPath, addonName);
67
+ await downloadAndExtract(addons[addonName], addonPath, addonName);
64
68
  addonsList.push(addonPath);
65
69
  }
66
70
  catch (e) {
package/dist/locale.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
+ import { fileURLToPath } from "node:url";
3
4
  import tags from "language-tags";
4
5
  import maxmind from "maxmind";
5
6
  import xml2js from "xml2js";
@@ -8,6 +9,7 @@ import { validateIP } from "./ip.js";
8
9
  import { GitHubDownloader, INSTALL_DIR, webdl } from "./pkgman.js";
9
10
  import { getAsBooleanFromENV } from "./utils.js";
10
11
  import { LeakWarning } from "./warnings.js";
12
+ const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
11
13
  export const ALLOW_GEOIP = true;
12
14
  class Locale {
13
15
  language;
@@ -182,7 +184,7 @@ export async function getGeolocation(ip) {
182
184
  return new Geolocation(locale, location.longitude, location.latitude, location.time_zone);
183
185
  }
184
186
  async function getUnicodeInfo() {
185
- const data = await fs.promises.readFile(path.join(import.meta.dirname, "data-files", "territoryInfo.xml"));
187
+ const data = await fs.promises.readFile(path.join(currentDir, "data-files", "territoryInfo.xml"));
186
188
  const parser = new xml2js.Parser();
187
189
  return parser.parseStringPromise(data);
188
190
  }
package/dist/pkgman.js CHANGED
@@ -3,6 +3,7 @@ import * as fs from "node:fs";
3
3
  import * as os from "node:os";
4
4
  import * as path from "node:path";
5
5
  import { setTimeout } from "node:timers/promises";
6
+ import { fileURLToPath } from "node:url";
6
7
  import AdmZip from "adm-zip";
7
8
  import ProgressBar from "progress";
8
9
  import { CONSTRAINTS } from "./__version__.js";
@@ -22,8 +23,9 @@ if (!(process.platform in OS_MAP)) {
22
23
  throw new UnsupportedOS(`OS ${process.platform} is not supported`);
23
24
  }
24
25
  export const OS_NAME = OS_MAP[process.platform];
26
+ const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
25
27
  export const INSTALL_DIR = userCacheDir("camoufox");
26
- export const LOCAL_DATA = path.join(import.meta.dirname, "data-files");
28
+ export const LOCAL_DATA = path.join(currentDir, "data-files");
27
29
  export const OS_ARCH_MATRIX = {
28
30
  win: ["x86_64", "i686"],
29
31
  mac: ["x86_64", "arm64"],
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
  }
@@ -321,7 +326,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
321
326
  throw new Error("OS must be set when using webgl_config");
322
327
  }
323
328
  // Add the default addons
324
- addDefaultAddons(addons, exclude_addons);
329
+ await addDefaultAddons(addons, exclude_addons);
325
330
  // Confirm all addon paths are valid
326
331
  if (addons.length > 0) {
327
332
  confirmPaths(addons);
@@ -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;
package/dist/warnings.js CHANGED
@@ -1,4 +1,7 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
1
3
  import WARNINGS_DATA from "./mappings/warnings.config.js";
4
+ const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
2
5
  export class LeakWarning extends Error {
3
6
  constructor(message) {
4
7
  super(message);
@@ -12,7 +15,7 @@ export class LeakWarning extends Error {
12
15
  if (iKnowWhatImDoing !== undefined) {
13
16
  warning += "\nIf this is intentional, pass `iKnowWhatImDoing=true`.";
14
17
  }
15
- const currentModule = import.meta.dirname;
18
+ const currentModule = currentDir;
16
19
  const originalStackTrace = Error.prepareStackTrace;
17
20
  Error.prepareStackTrace = (_, stack) => stack;
18
21
  const err = new Error();
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
2
3
  import { OS_ARCH_MATRIX } from "../pkgman.js";
3
4
  // Cached Database constructor - loaded lazily on first use
4
5
  let DatabaseConstructor = null;
@@ -10,7 +11,7 @@ let DatabaseConstructor = null;
10
11
  async function openDatabase(pathName) {
11
12
  if (!DatabaseConstructor) {
12
13
  if (typeof Bun !== "undefined") {
13
- // @ts-ignore - bun:sqlite only exists in Bun runtime
14
+ // @ts-expect-error - bun:sqlite only exists in Bun runtime
14
15
  const { Database: BunDatabase } = await import("bun:sqlite");
15
16
  DatabaseConstructor = BunDatabase;
16
17
  }
@@ -23,7 +24,8 @@ async function openDatabase(pathName) {
23
24
  return new DatabaseConstructor(pathName);
24
25
  }
25
26
  // Get database path relative to this file
26
- const DB_PATH = path.join(import.meta.dirname, "..", "data-files", "webgl_data.db");
27
+ const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
28
+ const DB_PATH = path.join(currentDir, "..", "data-files", "webgl_data.db");
27
29
  export async function sampleWebGL(os, vendor, renderer) {
28
30
  if (!OS_ARCH_MATRIX[os]) {
29
31
  throw new Error(`Invalid OS: ${os}. Must be one of: win, mac, lin`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camoufox-js",
3
- "version": "0.8.5",
3
+ "version": "0.9.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  "commander": "^14.0.0",
36
36
  "fingerprint-generator": "^2.1.66",
37
37
  "glob": "^13.0.0",
38
- "impit": "^0.7.0",
38
+ "impit": "^0.9.0",
39
39
  "language-tags": "^2.0.1",
40
40
  "maxmind": "^5.0.0",
41
41
  "progress": "^2.0.3",
@@ -43,7 +43,7 @@
43
43
  "xml2js": "^0.6.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@biomejs/biome": "2.3.11",
46
+ "@biomejs/biome": "2.4.0",
47
47
  "@types/adm-zip": "^0.5.7",
48
48
  "@types/better-sqlite3": "^7.6.13",
49
49
  "@types/language-tags": "^1.0.4",