camoufox-js 0.7.0 → 0.8.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/utils.js CHANGED
@@ -1,25 +1,25 @@
1
1
  // from browserforge.fingerprints import Fingerprint, Screen
2
2
  // from screeninfo import get_monitors
3
3
  // from ua_parser import user_agent_parser
4
- import path from 'path';
5
- import { addDefaultAddons, confirmPaths } from './addons.js';
6
- import { InvalidOS, InvalidPropertyType, NonFirefoxFingerprint, UnknownProperty } from './exceptions.js';
7
- import { fromBrowserforge, generateFingerprint, SUPPORTED_OS } from './fingerprints.js';
8
- import { publicIP, validIPv4, validIPv6 } from './ip.js';
9
- import { geoipAllowed, getGeolocation, handleLocales } from './locale.js';
10
- import { OS_NAME, getPath, installedVerStr, launchPath } from './pkgman.js';
11
- import { LeakWarning } from './warnings.js';
12
- import { sampleWebGL } from './webgl/sample.js';
13
- import { readFileSync } from 'fs';
14
- import { join } from 'path';
15
- import { UAParser } from 'ua-parser-js';
4
+ import { readFileSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { UAParser } from "ua-parser-js";
7
+ import { addDefaultAddons, confirmPaths, } from "./addons.js";
8
+ import { InvalidOS, InvalidPropertyType, NonFirefoxFingerprint, UnknownProperty, } from "./exceptions.js";
9
+ import { fromBrowserforge, generateFingerprint, SUPPORTED_OS, } from "./fingerprints.js";
10
+ import { publicIP, validIPv4, validIPv6 } from "./ip.js";
11
+ import { geoipAllowed, getGeolocation, handleLocales } from "./locale.js";
12
+ import FONTS from "./mappings/fonts.config.js";
13
+ import { getPath, installedVerStr, launchPath, OS_NAME } from "./pkgman.js";
14
+ import { LeakWarning } from "./warnings.js";
15
+ import { sampleWebGL } from "./webgl/sample.js";
16
16
  // Camoufox preferences to cache previous pages and requests
17
17
  const CACHE_PREFS = {
18
- 'browser.sessionhistory.max_entries': 10,
19
- 'browser.sessionhistory.max_total_viewers': -1,
20
- 'browser.cache.memory.enable': true,
21
- 'browser.cache.disk_cache_ssl': true,
22
- 'browser.cache.disk.smart_size.enabled': true,
18
+ "browser.sessionhistory.max_entries": 10,
19
+ "browser.sessionhistory.max_total_viewers": -1,
20
+ "browser.cache.memory.enable": true,
21
+ "browser.cache.disk_cache_ssl": true,
22
+ "browser.cache.disk.smart_size.enabled": true,
23
23
  };
24
24
  function getEnvVars(configMap, userAgentOS) {
25
25
  const envVars = {};
@@ -31,7 +31,7 @@ function getEnvVars(configMap, userAgentOS) {
31
31
  console.error(`Error updating config: ${e}`);
32
32
  process.exit(1);
33
33
  }
34
- const chunkSize = OS_NAME === 'win' ? 2047 : 32767;
34
+ const chunkSize = OS_NAME === "win" ? 2047 : 32767;
35
35
  const configStr = new TextDecoder().decode(updatedConfigData);
36
36
  for (let i = 0; i < configStr.length; i += chunkSize) {
37
37
  const chunk = configStr.slice(i, i + chunkSize);
@@ -44,15 +44,15 @@ function getEnvVars(configMap, userAgentOS) {
44
44
  process.exit(1);
45
45
  }
46
46
  }
47
- if (OS_NAME === 'lin') {
48
- const fontconfigPath = getPath(path.join('fontconfig', userAgentOS));
49
- envVars['FONTCONFIG_PATH'] = fontconfigPath;
47
+ if (OS_NAME === "lin") {
48
+ const fontconfigPath = getPath(path.join("fontconfig", userAgentOS));
49
+ envVars.FONTCONFIG_PATH = fontconfigPath;
50
50
  }
51
51
  return envVars;
52
52
  }
53
53
  export function getAsBooleanFromENV(name, defaultValue) {
54
54
  const value = process.env[name];
55
- if (value === 'false' || value === '0')
55
+ if (value === "false" || value === "0")
56
56
  return false;
57
57
  if (value)
58
58
  return true;
@@ -62,10 +62,10 @@ function loadProperties(filePath) {
62
62
  let propFile;
63
63
  filePath = filePath?.toString();
64
64
  if (filePath) {
65
- propFile = path.join(path.dirname(filePath), 'properties.json');
65
+ propFile = path.join(path.dirname(filePath), "properties.json");
66
66
  }
67
67
  else {
68
- propFile = getPath('properties.json');
68
+ propFile = getPath("properties.json");
69
69
  }
70
70
  const propData = readFileSync(propFile).toString();
71
71
  const propDict = JSON.parse(propData);
@@ -88,27 +88,27 @@ function validateConfig(configMap, path) {
88
88
  }
89
89
  function validateType(value, expectedType) {
90
90
  switch (expectedType) {
91
- case 'str':
92
- return typeof value === 'string';
93
- case 'int':
91
+ case "str":
92
+ return typeof value === "string";
93
+ case "int":
94
94
  return Number.isInteger(value);
95
- case 'uint':
95
+ case "uint":
96
96
  return Number.isInteger(value) && value >= 0;
97
- case 'double':
98
- return typeof value === 'number';
99
- case 'bool':
100
- return typeof value === 'boolean';
101
- case 'array':
97
+ case "double":
98
+ return typeof value === "number";
99
+ case "bool":
100
+ return typeof value === "boolean";
101
+ case "array":
102
102
  return Array.isArray(value);
103
- case 'dict':
104
- return typeof value === 'object' && value !== null && !Array.isArray(value);
103
+ case "dict":
104
+ return (typeof value === "object" && value !== null && !Array.isArray(value));
105
105
  default:
106
106
  return false;
107
107
  }
108
108
  }
109
109
  function getTargetOS(config) {
110
- if (config['navigator.userAgent']) {
111
- return determineUAOS(config['navigator.userAgent']);
110
+ if (config["navigator.userAgent"]) {
111
+ return determineUAOS(config["navigator.userAgent"]);
112
112
  }
113
113
  return OS_NAME;
114
114
  }
@@ -119,12 +119,12 @@ function determineUAOS(userAgent) {
119
119
  throw new Error("Could not determine OS from user agent");
120
120
  }
121
121
  if (parsedUA.startsWith("macOS")) {
122
- return 'mac';
122
+ return "mac";
123
123
  }
124
124
  if (parsedUA.startsWith("Windows")) {
125
- return 'win';
125
+ return "win";
126
126
  }
127
- return 'lin';
127
+ return "lin";
128
128
  }
129
129
  function getScreenCons(headless) {
130
130
  if (headless === false) {
@@ -144,8 +144,7 @@ function getScreenCons(headless) {
144
144
  return undefined;
145
145
  }
146
146
  function updateFonts(config, targetOS) {
147
- const fontsPath = join(import.meta.dirname, 'data-files', 'fonts.json');
148
- const fonts = JSON.parse(readFileSync(fontsPath, 'utf-8'))[targetOS];
147
+ const fonts = FONTS[targetOS];
149
148
  if (config.fonts) {
150
149
  config.fonts = Array.from(new Set([...fonts, ...config.fonts]));
151
150
  }
@@ -155,11 +154,11 @@ function updateFonts(config, targetOS) {
155
154
  }
156
155
  function checkCustomFingerprint(fingerprint) {
157
156
  const parser = new UAParser(fingerprint.navigator.userAgent);
158
- const browserName = parser.getBrowser().name || 'Non-Firefox';
159
- if (browserName !== 'Firefox') {
157
+ const browserName = parser.getBrowser().name || "Non-Firefox";
158
+ if (browserName !== "Firefox") {
160
159
  throw new NonFirefoxFingerprint(`"${browserName}" fingerprints are not supported in Camoufox. Using fingerprints from a browser other than Firefox WILL lead to detection. If this is intentional, pass i_know_what_im_doing=True.`);
161
160
  }
162
- LeakWarning.warn('custom_fingerprint', false);
161
+ LeakWarning.warn("custom_fingerprint", false);
163
162
  }
164
163
  function validateOS(os) {
165
164
  if (!os)
@@ -173,7 +172,7 @@ function validateOS(os) {
173
172
  }
174
173
  return [os];
175
174
  }
176
- function cleanLocals(data) {
175
+ function _cleanLocals(data) {
177
176
  delete data.playwright;
178
177
  delete data.persistentContext;
179
178
  return data;
@@ -191,31 +190,31 @@ function setInto(target, key, value) {
191
190
  }
192
191
  }
193
192
  function isDomainSet(config, ...properties) {
194
- return properties.some(prop => {
195
- if (prop.endsWith('.') || prop.endsWith(':')) {
196
- return Object.keys(config).some(key => key.startsWith(prop));
193
+ return properties.some((prop) => {
194
+ if (prop.endsWith(".") || prop.endsWith(":")) {
195
+ return Object.keys(config).some((key) => key.startsWith(prop));
197
196
  }
198
197
  return prop in config;
199
198
  });
200
199
  }
201
200
  function warnManualConfig(config) {
202
- if (isDomainSet(config, 'navigator.language', 'navigator.languages', 'headers.Accept-Language', 'locale:')) {
203
- LeakWarning.warn('locale', false);
201
+ if (isDomainSet(config, "navigator.language", "navigator.languages", "headers.Accept-Language", "locale:")) {
202
+ LeakWarning.warn("locale", false);
204
203
  }
205
- if (isDomainSet(config, 'geolocation:', 'timezone')) {
206
- LeakWarning.warn('geolocation', false);
204
+ if (isDomainSet(config, "geolocation:", "timezone")) {
205
+ LeakWarning.warn("geolocation", false);
207
206
  }
208
- if (isDomainSet(config, 'headers.User-Agent')) {
209
- LeakWarning.warn('header-ua', false);
207
+ if (isDomainSet(config, "headers.User-Agent")) {
208
+ LeakWarning.warn("header-ua", false);
210
209
  }
211
- if (isDomainSet(config, 'navigator.')) {
212
- LeakWarning.warn('navigator', false);
210
+ if (isDomainSet(config, "navigator.")) {
211
+ LeakWarning.warn("navigator", false);
213
212
  }
214
- if (isDomainSet(config, 'screen.', 'window.', 'document.body.')) {
215
- LeakWarning.warn('viewport', false);
213
+ if (isDomainSet(config, "screen.", "window.", "document.body.")) {
214
+ LeakWarning.warn("viewport", false);
216
215
  }
217
216
  }
218
- async function asyncAttachVD(browser, virtualDisplay) {
217
+ async function _asyncAttachVD(browser, virtualDisplay) {
219
218
  if (!virtualDisplay) {
220
219
  return browser;
221
220
  }
@@ -233,7 +232,8 @@ export function syncAttachVD(browser, virtualDisplay) {
233
232
  /**
234
233
  * Attaches the virtual display to the sync browser cleanup
235
234
  */
236
- if (!virtualDisplay) { // Skip if no virtual display is provided
235
+ if (!virtualDisplay) {
236
+ // Skip if no virtual display is provided
237
237
  return browser;
238
238
  }
239
239
  const originalClose = browser.close;
@@ -254,7 +254,7 @@ export function syncAttachVD(browser, virtualDisplay) {
254
254
  function getProxyUrl(proxy) {
255
255
  if (!proxy)
256
256
  return null;
257
- if (typeof proxy === 'string') {
257
+ if (typeof proxy === "string") {
258
258
  return new URL(proxy);
259
259
  }
260
260
  const { server, username, password } = proxy;
@@ -265,10 +265,10 @@ function getProxyUrl(proxy) {
265
265
  // In both of these cases, we need to try re-parse URL with `http://` prefix.
266
266
  url = new URL(server);
267
267
  if (!url.host || !url.protocol)
268
- url = new URL('http://' + server);
268
+ url = new URL(`http://${server}`);
269
269
  }
270
- catch (e) {
271
- url = new URL('http://' + server);
270
+ catch (_e) {
271
+ url = new URL(`http://${server}`);
272
272
  }
273
273
  if (username)
274
274
  url.username = username;
@@ -303,13 +303,13 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
303
303
  if (!env) {
304
304
  env = process.env;
305
305
  }
306
- if (typeof executable_path === 'string') {
306
+ if (typeof executable_path === "string") {
307
307
  // Convert executable path to a Path object
308
308
  executable_path = path.resolve(executable_path);
309
309
  }
310
310
  // Handle virtual display
311
311
  if (virtual_display) {
312
- env['DISPLAY'] = virtual_display;
312
+ env.DISPLAY = virtual_display;
313
313
  }
314
314
  // Warn the user for manual config settings
315
315
  if (!i_know_what_im_doing) {
@@ -318,28 +318,28 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
318
318
  const operatingSystems = validateOS(os);
319
319
  // webgl_config requires OS to be set
320
320
  if (!operatingSystems && webgl_config) {
321
- throw new Error('OS must be set when using webgl_config');
321
+ throw new Error("OS must be set when using webgl_config");
322
322
  }
323
323
  // Add the default addons
324
324
  addDefaultAddons(addons, exclude_addons);
325
325
  // Confirm all addon paths are valid
326
326
  if (addons.length > 0) {
327
327
  confirmPaths(addons);
328
- config['addons'] = addons;
328
+ config.addons = addons;
329
329
  }
330
330
  // Get the Firefox version
331
331
  let ff_version_str;
332
332
  if (ff_version) {
333
333
  ff_version_str = ff_version.toString();
334
- LeakWarning.warn('ff_version', i_know_what_im_doing);
334
+ LeakWarning.warn("ff_version", i_know_what_im_doing);
335
335
  }
336
336
  else {
337
- ff_version_str = installedVerStr().split('.', 1)[0];
337
+ ff_version_str = installedVerStr().split(".", 1)[0];
338
338
  }
339
339
  // Generate a fingerprint
340
340
  if (!fingerprint) {
341
341
  fingerprint = generateFingerprint(window, {
342
- screen: screen || getScreenCons(headless || 'DISPLAY' in env),
342
+ screen: screen || getScreenCons(headless || "DISPLAY" in env),
343
343
  operatingSystems,
344
344
  });
345
345
  }
@@ -353,27 +353,27 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
353
353
  mergeInto(config, fromBrowserforge(fingerprint, ff_version_str));
354
354
  const targetOS = getTargetOS(config);
355
355
  // Set a random window.history.length
356
- setInto(config, 'window.history.length', Math.floor(Math.random() * 5) + 1);
356
+ setInto(config, "window.history.length", Math.floor(Math.random() * 5) + 1);
357
357
  // Update fonts list
358
358
  if (fonts) {
359
- config['fonts'] = fonts;
359
+ config.fonts = fonts;
360
360
  }
361
361
  if (custom_fonts_only) {
362
- firefox_user_prefs['gfx.bundled-fonts.activate'] = 0;
362
+ firefox_user_prefs["gfx.bundled-fonts.activate"] = 0;
363
363
  if (fonts) {
364
364
  // The user has passed their own fonts, and OS fonts are disabled.
365
- LeakWarning.warn('custom_fonts_only');
365
+ LeakWarning.warn("custom_fonts_only");
366
366
  }
367
367
  else {
368
368
  // OS fonts are disabled, and the user has not passed their own fonts either.
369
- throw new Error('No custom fonts were passed, but `custom_fonts_only` is enabled.');
369
+ throw new Error("No custom fonts were passed, but `custom_fonts_only` is enabled.");
370
370
  }
371
371
  }
372
372
  else {
373
373
  updateFonts(config, targetOS);
374
374
  }
375
375
  // Set a fixed font spacing seed
376
- setInto(config, 'fonts:spacing_seed', Math.floor(Math.random() * 1_073_741_824));
376
+ setInto(config, "fonts:spacing_seed", Math.floor(Math.random() * 1_073_741_824));
377
377
  // Handle proxy
378
378
  const proxyUrl = getProxyUrl(proxy);
379
379
  // Set geolocation
@@ -384,11 +384,11 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
384
384
  // Spoof WebRTC if not blocked
385
385
  if (!block_webrtc) {
386
386
  if (validIPv4(geoip)) {
387
- setInto(config, 'webrtc:ipv4', geoip);
388
- firefox_user_prefs['network.dns.disableIPv6'] = true;
387
+ setInto(config, "webrtc:ipv4", geoip);
388
+ firefox_user_prefs["network.dns.disableIPv6"] = true;
389
389
  }
390
390
  else if (validIPv6(geoip)) {
391
- setInto(config, 'webrtc:ipv6', geoip);
391
+ setInto(config, "webrtc:ipv6", geoip);
392
392
  }
393
393
  }
394
394
  const geolocation = await getGeolocation(geoip);
@@ -397,9 +397,9 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
397
397
  // Raise a warning when a proxy is being used without spoofing geolocation.
398
398
  // This is a very bad idea; the warning cannot be ignored with i_know_what_im_doing.
399
399
  if (proxyUrl &&
400
- !proxyUrl.hostname.includes('localhost') &&
401
- !isDomainSet(config, 'geolocation:')) {
402
- LeakWarning.warn('proxy_without_geoip');
400
+ !proxyUrl.hostname.includes("localhost") &&
401
+ !isDomainSet(config, "geolocation:")) {
402
+ LeakWarning.warn("proxy_without_geoip");
403
403
  }
404
404
  // Set locale
405
405
  if (locale) {
@@ -407,31 +407,32 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
407
407
  }
408
408
  // Pass the humanize option
409
409
  if (humanize) {
410
- setInto(config, 'humanize', true);
411
- if (typeof humanize === 'number') {
412
- setInto(config, 'humanize:maxTime', humanize);
410
+ setInto(config, "humanize", true);
411
+ if (typeof humanize === "number") {
412
+ setInto(config, "humanize:maxTime", humanize);
413
413
  }
414
414
  }
415
415
  // Enable the main world context creation
416
416
  if (main_world_eval) {
417
- setInto(config, 'allowMainWorld', true);
417
+ setInto(config, "allowMainWorld", true);
418
418
  }
419
419
  // Set Firefox user preferences
420
420
  if (block_images) {
421
- LeakWarning.warn('block_images', i_know_what_im_doing);
422
- firefox_user_prefs['permissions.default.image'] = 2;
421
+ LeakWarning.warn("block_images", i_know_what_im_doing);
422
+ firefox_user_prefs["permissions.default.image"] = 2;
423
423
  }
424
424
  if (block_webrtc) {
425
- firefox_user_prefs['media.peerconnection.enabled'] = false;
425
+ firefox_user_prefs["media.peerconnection.enabled"] = false;
426
426
  }
427
427
  if (disable_coop) {
428
- LeakWarning.warn('disable_coop', i_know_what_im_doing);
429
- firefox_user_prefs['browser.tabs.remote.useCrossOriginOpenerPolicy'] = false;
428
+ LeakWarning.warn("disable_coop", i_know_what_im_doing);
429
+ firefox_user_prefs["browser.tabs.remote.useCrossOriginOpenerPolicy"] =
430
+ false;
430
431
  }
431
432
  // Allow allow_webgl parameter for backwards compatibility
432
433
  if (block_webgl || launch_options.allow_webgl === false) {
433
- firefox_user_prefs['webgl.disabled'] = true;
434
- LeakWarning.warn('block_webgl', i_know_what_im_doing);
434
+ firefox_user_prefs["webgl.disabled"] = true;
435
+ LeakWarning.warn("block_webgl", i_know_what_im_doing);
435
436
  }
436
437
  else {
437
438
  // If the user has provided a specific WebGL vendor/renderer pair, use it
@@ -447,14 +448,14 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
447
448
  mergeInto(config, webGlConfig);
448
449
  // Set the WebGL preferences
449
450
  mergeInto(firefox_user_prefs, {
450
- 'webgl.enable-webgl2': webGl2Enabled,
451
- 'webgl.force-enabled': true,
451
+ "webgl.enable-webgl2": webGl2Enabled,
452
+ "webgl.force-enabled": true,
452
453
  });
453
454
  }
454
455
  // Canvas anti-fingerprinting
455
456
  mergeInto(config, {
456
- 'canvas:aaOffset': Math.floor(Math.random() * 101) - 50, // nosec
457
- 'canvas:aaCapOffset': true,
457
+ "canvas:aaOffset": Math.floor(Math.random() * 101) - 50, // nosec
458
+ "canvas:aaCapOffset": true,
458
459
  });
459
460
  // Cache previous pages, requests, etc (uses more memory)
460
461
  if (enable_cache) {
@@ -462,7 +463,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
462
463
  }
463
464
  // Print the config if debug is enabled
464
465
  if (debug) {
465
- console.debug('[DEBUG] Config:');
466
+ console.debug("[DEBUG] Config:");
466
467
  console.debug(config);
467
468
  }
468
469
  // Validate the config
@@ -480,17 +481,19 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
480
481
  executable_path = launchPath();
481
482
  }
482
483
  const out = {
483
- "executablePath": executable_path,
484
- "args": args,
485
- "env": env_vars,
486
- "firefoxUserPrefs": firefox_user_prefs,
487
- "proxy": proxyUrl ? {
488
- server: proxyUrl.origin,
489
- username: proxyUrl.username,
490
- password: proxyUrl.password,
491
- bypass: typeof proxy === 'string' ? undefined : proxy?.bypass,
492
- } : undefined,
493
- "headless": headless,
484
+ executablePath: executable_path,
485
+ args: args,
486
+ env: env_vars,
487
+ firefoxUserPrefs: firefox_user_prefs,
488
+ proxy: proxyUrl
489
+ ? {
490
+ server: proxyUrl.origin,
491
+ username: proxyUrl.username,
492
+ password: proxyUrl.password,
493
+ bypass: typeof proxy === "string" ? undefined : proxy?.bypass,
494
+ }
495
+ : undefined,
496
+ headless: headless,
494
497
  ...launch_options,
495
498
  };
496
499
  return out;
@@ -1,10 +1,10 @@
1
- import { CannotExecuteXvfb, CannotFindXvfb, VirtualDisplayNotSupported, } from './exceptions.js';
2
- import { OS_NAME } from './pkgman.js';
3
- import { execFileSync, spawn } from 'child_process';
4
- import { existsSync } from 'fs';
5
- import { tmpdir } from 'os';
1
+ import { execFileSync, spawn } from "node:child_process";
6
2
  // import { globSync } from 'glob';
7
- import { randomInt } from 'crypto';
3
+ import { randomInt } from "node:crypto";
4
+ import { existsSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { CannotExecuteXvfb, CannotFindXvfb, VirtualDisplayNotSupported, } from "./exceptions.js";
7
+ import { OS_NAME } from "./pkgman.js";
8
8
  // import { Lock } from 'async-mutex';
9
9
  export class VirtualDisplay {
10
10
  debug;
@@ -16,27 +16,37 @@ export class VirtualDisplay {
16
16
  }
17
17
  get xvfb_args() {
18
18
  return [
19
- "-screen", "0", "1x1x24",
19
+ "-screen",
20
+ "0",
21
+ "1x1x24",
20
22
  "-ac",
21
- "-nolisten", "tcp",
22
- "-extension", "RENDER",
23
- "+extension", "GLX",
24
- "-extension", "COMPOSITE",
25
- "-extension", "XVideo",
26
- "-extension", "XVideo-MotionCompensation",
27
- "-extension", "XINERAMA",
23
+ "-nolisten",
24
+ "tcp",
25
+ "-extension",
26
+ "RENDER",
27
+ "+extension",
28
+ "GLX",
29
+ "-extension",
30
+ "COMPOSITE",
31
+ "-extension",
32
+ "XVideo",
33
+ "-extension",
34
+ "XVideo-MotionCompensation",
35
+ "-extension",
36
+ "XINERAMA",
28
37
  "-shmem",
29
- "-fp", "built-ins",
38
+ "-fp",
39
+ "built-ins",
30
40
  "-nocursor",
31
41
  "-br",
32
42
  ];
33
43
  }
34
44
  get xvfb_path() {
35
- const path = execFileSync('which', ['Xvfb']).toString().trim();
45
+ const path = execFileSync("which", ["Xvfb"]).toString().trim();
36
46
  if (!path) {
37
47
  throw new CannotFindXvfb("Please install Xvfb to use headless mode.");
38
48
  }
39
- if (!existsSync(path) || !execFileSync('test', ['-x', path])) {
49
+ if (!existsSync(path) || !execFileSync("test", ["-x", path])) {
40
50
  throw new CannotExecuteXvfb(`I do not have permission to execute Xvfb: ${path}`);
41
51
  }
42
52
  return path;
@@ -46,10 +56,10 @@ export class VirtualDisplay {
46
56
  }
47
57
  execute_xvfb() {
48
58
  if (this.debug) {
49
- console.log('Starting virtual display:', this.xvfb_cmd.join(' '));
59
+ console.log("Starting virtual display:", this.xvfb_cmd.join(" "));
50
60
  }
51
61
  this.proc = spawn(this.xvfb_cmd[0], this.xvfb_cmd.slice(1), {
52
- stdio: this.debug ? 'inherit' : 'ignore',
62
+ stdio: this.debug ? "inherit" : "ignore",
53
63
  detached: true,
54
64
  });
55
65
  }
@@ -69,14 +79,14 @@ export class VirtualDisplay {
69
79
  // this._lock.runExclusive(() => {
70
80
  if (this.proc && !this.proc.killed) {
71
81
  if (this.debug) {
72
- console.log('Terminating virtual display:', this.display);
82
+ console.log("Terminating virtual display:", this.display);
73
83
  }
74
84
  this.proc.kill();
75
85
  }
76
86
  // });
77
87
  }
78
88
  static _get_lock_files() {
79
- const tmpd = process.env.TMPDIR || tmpdir();
89
+ const _tmpd = process.env.TMPDIR || tmpdir();
80
90
  try {
81
91
  return [];
82
92
  // return globSync(join(tmpd, ".X*-lock")).filter(p => existsSync(p));
@@ -86,7 +96,7 @@ export class VirtualDisplay {
86
96
  }
87
97
  }
88
98
  static _free_display() {
89
- const ls = VirtualDisplay._get_lock_files().map(x => parseInt(x.split("X")[1].split("-")[0]));
99
+ const ls = VirtualDisplay._get_lock_files().map((x) => parseInt(x.split("X")[1].split("-")[0], 10));
90
100
  return ls.length ? Math.max(99, Math.max(...ls) + randomInt(3, 20)) : 99;
91
101
  }
92
102
  get display() {
@@ -96,7 +106,7 @@ export class VirtualDisplay {
96
106
  return this._display;
97
107
  }
98
108
  static assert_linux() {
99
- if (OS_NAME !== 'lin') {
109
+ if (OS_NAME !== "lin") {
100
110
  throw new VirtualDisplayNotSupported("Virtual display is only supported on Linux.");
101
111
  }
102
112
  }
package/dist/warnings.js CHANGED
@@ -1,10 +1,8 @@
1
- import { join } from 'path';
2
- import { loadYaml } from './pkgman.js';
3
- const WARNINGS_DATA = loadYaml(join(import.meta.dirname, 'data-files', 'warnings.yml'));
1
+ import WARNINGS_DATA from "./mappings/warnings.config.js";
4
2
  export class LeakWarning extends Error {
5
3
  constructor(message) {
6
4
  super(message);
7
- this.name = 'LeakWarning';
5
+ this.name = "LeakWarning";
8
6
  }
9
7
  static warn(warningKey, iKnowWhatImDoing) {
10
8
  let warning = WARNINGS_DATA[warningKey];
@@ -12,7 +10,7 @@ export class LeakWarning extends Error {
12
10
  return;
13
11
  }
14
12
  if (iKnowWhatImDoing !== undefined) {
15
- warning += '\nIf this is intentional, pass `iKnowWhatImDoing=true`.';
13
+ warning += "\nIf this is intentional, pass `iKnowWhatImDoing=true`.";
16
14
  }
17
15
  const currentModule = import.meta.dirname;
18
16
  const originalStackTrace = Error.prepareStackTrace;
@@ -7,7 +7,7 @@ interface WebGLData {
7
7
  lin: number;
8
8
  webGl2Enabled: boolean;
9
9
  }
10
- export declare function sampleWebGL(os: 'win' | 'mac' | 'lin', vendor?: string, renderer?: string): Promise<WebGLData>;
10
+ export declare function sampleWebGL(os: "win" | "mac" | "lin", vendor?: string, renderer?: string): Promise<WebGLData>;
11
11
  interface VendorRenderer {
12
12
  vendor: string;
13
13
  renderer: string;