camoufox-js 0.11.1 → 0.11.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/ip.js CHANGED
@@ -55,6 +55,31 @@ export function validateIP(ip) {
55
55
  throw new InvalidIP(`Invalid IP address: ${ip}`);
56
56
  }
57
57
  }
58
+ // Impit has no close/dispose API: each instance's native client (Tokio
59
+ // runtime resources, one UDP resolver socket) is only reclaimed when the
60
+ // JS wrapper is GC'd — and V8 rarely collects the tiny wrappers, so
61
+ // per-call instances leak fds in long-running processes. Reuse instances
62
+ // via a small LRU keyed by proxy URL; evicted entries are reclaimed by GC.
63
+ const IMPIT_CACHE_MAX = 8;
64
+ const impitCache = new Map();
65
+ function getImpit(proxy) {
66
+ const key = proxy;
67
+ const cached = impitCache.get(key);
68
+ if (cached) {
69
+ impitCache.delete(key);
70
+ impitCache.set(key, cached);
71
+ return cached;
72
+ }
73
+ const impit = new Impit({
74
+ proxyUrl: proxy,
75
+ timeout: 5000,
76
+ });
77
+ impitCache.set(key, impit);
78
+ if (impitCache.size > IMPIT_CACHE_MAX) {
79
+ impitCache.delete(impitCache.keys().next().value);
80
+ }
81
+ return impit;
82
+ }
58
83
  export async function publicIP(proxy) {
59
84
  const URLS = [
60
85
  "https://api.ipify.org",
@@ -67,11 +92,7 @@ export async function publicIP(proxy) {
67
92
  const errors = [];
68
93
  for (const url of URLS) {
69
94
  try {
70
- const impit = new Impit({
71
- proxyUrl: proxy,
72
- timeout: 5000,
73
- });
74
- const response = await impit.fetch(url);
95
+ const response = await getImpit(proxy).fetch(url);
75
96
  if (!response.ok) {
76
97
  continue;
77
98
  }
package/dist/pkgman.js CHANGED
@@ -146,6 +146,8 @@ export class GitHubDownloader {
146
146
  }
147
147
  const releases = await response.json();
148
148
  for (const release of releases) {
149
+ if (release.prerelease || release.draft)
150
+ continue;
149
151
  for (const asset of release.assets) {
150
152
  const data = this.checkAsset(asset);
151
153
  if (data) {
@@ -222,11 +224,12 @@ export class CamoufoxFetcher extends GitHubDownloader {
222
224
  async install() {
223
225
  await this.init();
224
226
  await CamoufoxFetcher.cleanup();
227
+ // Set up outside the try so finally can always tear down the ~600MB staging dir.
228
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "camoufox-"));
229
+ const tempFilePath = path.join(tempDir, "camoufox.zip");
230
+ const tempFileStream = fs.createWriteStream(tempFilePath);
225
231
  try {
226
232
  fs.mkdirSync(INSTALL_DIR, { recursive: true });
227
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "camoufox-"));
228
- const tempFilePath = path.join(tempDir, "camoufox.zip");
229
- const tempFileStream = fs.createWriteStream(tempFilePath);
230
233
  await webdl(this.url, "Downloading Camoufox...", true, tempFileStream);
231
234
  await new Promise((r) => tempFileStream.close(r));
232
235
  await this.extractZip(tempFilePath);
@@ -241,6 +244,19 @@ export class CamoufoxFetcher extends GitHubDownloader {
241
244
  await CamoufoxFetcher.cleanup();
242
245
  throw e;
243
246
  }
247
+ finally {
248
+ // Best-effort teardown: a throw here would mask the real result, and the caller is fire-and-forget.
249
+ try {
250
+ // Close before removing: Windows can't unlink a file with an open handle.
251
+ if (!tempFileStream.closed) {
252
+ await new Promise((resolve) => tempFileStream.close(() => resolve()));
253
+ }
254
+ fs.rmSync(tempDir, { recursive: true, force: true });
255
+ }
256
+ catch (cleanupErr) {
257
+ console.error(`Failed to remove staging dir ${tempDir}: ${cleanupErr}`);
258
+ }
259
+ }
244
260
  }
245
261
  get url() {
246
262
  if (!this._url) {
package/dist/utils.js CHANGED
@@ -218,11 +218,15 @@ async function _asyncAttachVD(browser, virtualDisplay) {
218
218
  if (!virtualDisplay) {
219
219
  return browser;
220
220
  }
221
- const originalClose = browser.close;
221
+ const originalClose = browser.close.bind(browser);
222
222
  browser.close = async (...args) => {
223
- await originalClose.apply(browser, ...args);
224
- if (virtualDisplay) {
225
- virtualDisplay.kill();
223
+ try {
224
+ return await originalClose(...args);
225
+ }
226
+ finally {
227
+ if (virtualDisplay) {
228
+ virtualDisplay.kill();
229
+ }
226
230
  }
227
231
  };
228
232
  browser._virtualDisplay = virtualDisplay;
@@ -236,11 +240,15 @@ export function syncAttachVD(browser, virtualDisplay) {
236
240
  // Skip if no virtual display is provided
237
241
  return browser;
238
242
  }
239
- const originalClose = browser.close;
240
- browser.close = (...args) => {
241
- originalClose.apply(browser, ...args);
242
- if (virtualDisplay) {
243
- virtualDisplay.kill();
243
+ const originalClose = browser.close.bind(browser);
244
+ browser.close = async (...args) => {
245
+ try {
246
+ return await originalClose(...args);
247
+ }
248
+ finally {
249
+ if (virtualDisplay) {
250
+ virtualDisplay.kill();
251
+ }
244
252
  }
245
253
  };
246
254
  browser._virtualDisplay = virtualDisplay;
@@ -356,6 +364,17 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
356
364
  }
357
365
  // Inject the fingerprint into the config
358
366
  mergeInto(config, fromBrowserforge(fingerprint, ff_version_str));
367
+ // Add seeds (BrowserForge doesn't generate these). Mirrors fingerprints.py,
368
+ // which seeds these right after from_browserforge() with setdefault. Range is
369
+ // 1..2^32-1 — 0 is excluded because it's a no-op in the C++ managers. Without
370
+ // a per-launch audio:seed the AudioFingerprintManager defaults to 0, so every
371
+ // spoofed context returns identical audio samples — a "same machine behind
372
+ // many identities" tell on CreepJS. setInto is "set only if unset", so a
373
+ // caller-supplied seed wins (the JS equivalent of setdefault).
374
+ const randint = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
375
+ setInto(config, "fonts:spacing_seed", randint(1, 4_294_967_295));
376
+ setInto(config, "audio:seed", randint(1, 4_294_967_295));
377
+ setInto(config, "canvas:seed", randint(1, 4_294_967_295));
359
378
  const targetOS = getTargetOS(config);
360
379
  // Set a random window.history.length
361
380
  setInto(config, "window.history.length", Math.floor(Math.random() * 5) + 1);
@@ -377,8 +396,6 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
377
396
  else {
378
397
  updateFonts(config, targetOS);
379
398
  }
380
- // Set a fixed font spacing seed
381
- setInto(config, "fonts:spacing_seed", Math.floor(Math.random() * 1_073_741_824));
382
399
  // Handle proxy
383
400
  const proxyUrl = getProxyUrl(proxy);
384
401
  // Set geolocation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camoufox-js",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": "dist/__main__.js",