camoufox-js 0.8.4 → 0.9.0

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/utils.js CHANGED
@@ -321,7 +321,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
321
321
  throw new Error("OS must be set when using webgl_config");
322
322
  }
323
323
  // Add the default addons
324
- addDefaultAddons(addons, exclude_addons);
324
+ await addDefaultAddons(addons, exclude_addons);
325
325
  // Confirm all addon paths are valid
326
326
  if (addons.length > 0) {
327
327
  confirmPaths(addons);
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,13 +1,36 @@
1
1
  import path from "node:path";
2
- import Database from "better-sqlite3";
2
+ import { fileURLToPath } from "node:url";
3
3
  import { OS_ARCH_MATRIX } from "../pkgman.js";
4
+ // Cached Database constructor - loaded lazily on first use
5
+ let DatabaseConstructor = null;
6
+ /**
7
+ * Opens a SQLite database using the appropriate driver for the runtime.
8
+ * Uses bun:sqlite in Bun, better-sqlite3 in Node.js.
9
+ * The Database constructor is cached after first load.
10
+ */
11
+ async function openDatabase(pathName) {
12
+ if (!DatabaseConstructor) {
13
+ if (typeof Bun !== "undefined") {
14
+ // @ts-ignore - bun:sqlite only exists in Bun runtime
15
+ const { Database: BunDatabase } = await import("bun:sqlite");
16
+ DatabaseConstructor = BunDatabase;
17
+ }
18
+ else {
19
+ const { default: NodeDatabase } = await import("better-sqlite3");
20
+ DatabaseConstructor = NodeDatabase;
21
+ }
22
+ }
23
+ // DatabaseConstructor is guaranteed to be set at this point
24
+ return new DatabaseConstructor(pathName);
25
+ }
4
26
  // Get database path relative to this file
5
- 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");
6
29
  export async function sampleWebGL(os, vendor, renderer) {
7
30
  if (!OS_ARCH_MATRIX[os]) {
8
31
  throw new Error(`Invalid OS: ${os}. Must be one of: win, mac, lin`);
9
32
  }
10
- const db = new Database(DB_PATH);
33
+ const db = await openDatabase(DB_PATH);
11
34
  let query = "";
12
35
  let params = [];
13
36
  if (vendor && renderer) {
@@ -63,7 +86,7 @@ export async function sampleWebGL(os, vendor, renderer) {
63
86
  });
64
87
  }
65
88
  export async function getPossiblePairs() {
66
- const db = new Database(DB_PATH);
89
+ const db = await openDatabase(DB_PATH);
67
90
  const result = {};
68
91
  return new Promise((resolve, reject) => {
69
92
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camoufox-js",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
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.8",
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",