camoufox-js 0.2.1 → 0.3.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/utils.d.ts +2 -1
- package/dist/utils.js +39 -18
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { DefaultAddons } from './addons.js';
|
|
|
2
2
|
import { VirtualDisplay } from './virtdisplay.js';
|
|
3
3
|
import { PathLike } from 'fs';
|
|
4
4
|
import { Fingerprint, FingerprintGeneratorOptions } from 'fingerprint-generator';
|
|
5
|
+
import { LaunchOptions as PlaywrightLaunchOptions } from 'playwright';
|
|
5
6
|
type Screen = FingerprintGeneratorOptions['screen'];
|
|
6
7
|
export declare function getAsBooleanFromENV(name: string, defaultValue?: boolean | undefined): boolean;
|
|
7
8
|
export declare function syncAttachVD(browser: any, virtualDisplay?: VirtualDisplay | null): any;
|
|
@@ -67,7 +68,7 @@ export interface LaunchOptions {
|
|
|
67
68
|
/** Proxy to use for the browser.
|
|
68
69
|
* Note: If `geoip` is `true`, a request will be sent through this proxy to find the target IP.
|
|
69
70
|
*/
|
|
70
|
-
proxy?: string;
|
|
71
|
+
proxy?: string | PlaywrightLaunchOptions['proxy'];
|
|
71
72
|
/** Cache previous pages, requests, etc. (uses more memory). */
|
|
72
73
|
enable_cache?: boolean;
|
|
73
74
|
/** Arguments to pass to the browser. */
|
package/dist/utils.js
CHANGED
|
@@ -247,6 +247,34 @@ export function syncAttachVD(browser, virtualDisplay) {
|
|
|
247
247
|
browser._virtualDisplay = virtualDisplay;
|
|
248
248
|
return browser;
|
|
249
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Convert a Playwright proxy string to a URL object.
|
|
252
|
+
*
|
|
253
|
+
* Implementation from https://github.com/microsoft/playwright/blob/3873b72ac1441ca691f7594f0ed705bd84518f93/packages/playwright-core/src/server/browserContext.ts#L737-L747
|
|
254
|
+
*/
|
|
255
|
+
function getProxyUrl(proxy) {
|
|
256
|
+
if (typeof proxy === 'string') {
|
|
257
|
+
return new URL(proxy);
|
|
258
|
+
}
|
|
259
|
+
const { server, username, password } = proxy;
|
|
260
|
+
let url;
|
|
261
|
+
try {
|
|
262
|
+
// new URL('127.0.0.1:8080') throws
|
|
263
|
+
// new URL('localhost:8080') fails to parse host or protocol
|
|
264
|
+
// In both of these cases, we need to try re-parse URL with `http://` prefix.
|
|
265
|
+
url = new URL(server);
|
|
266
|
+
if (!url.host || !url.protocol)
|
|
267
|
+
url = new URL('http://' + server);
|
|
268
|
+
}
|
|
269
|
+
catch (e) {
|
|
270
|
+
url = new URL('http://' + server);
|
|
271
|
+
}
|
|
272
|
+
if (username)
|
|
273
|
+
url.username = username;
|
|
274
|
+
if (password)
|
|
275
|
+
url.password = password;
|
|
276
|
+
return url;
|
|
277
|
+
}
|
|
250
278
|
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 }) {
|
|
251
279
|
// Build the config
|
|
252
280
|
if (!config) {
|
|
@@ -348,16 +376,13 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
348
376
|
}
|
|
349
377
|
// Set a fixed font spacing seed
|
|
350
378
|
setInto(config, 'fonts:spacing_seed', Math.floor(Math.random() * 1_073_741_824));
|
|
379
|
+
// Handle proxy
|
|
380
|
+
const proxyUrl = proxy ? getProxyUrl(proxy) : undefined;
|
|
351
381
|
// Set geolocation
|
|
352
382
|
if (geoip) {
|
|
353
383
|
geoipAllowed();
|
|
354
384
|
// Find the user's IP address
|
|
355
|
-
|
|
356
|
-
geoip = await publicIP(proxy);
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
geoip = await publicIP();
|
|
360
|
-
}
|
|
385
|
+
geoip = await publicIP(proxyUrl?.href);
|
|
361
386
|
// Spoof WebRTC if not blocked
|
|
362
387
|
if (!block_webrtc) {
|
|
363
388
|
if (validIPv4(geoip)) {
|
|
@@ -373,8 +398,8 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
373
398
|
}
|
|
374
399
|
// Raise a warning when a proxy is being used without spoofing geolocation.
|
|
375
400
|
// This is a very bad idea; the warning cannot be ignored with i_know_what_im_doing.
|
|
376
|
-
if (
|
|
377
|
-
!
|
|
401
|
+
if (proxyUrl &&
|
|
402
|
+
!proxyUrl.hostname.includes('localhost') &&
|
|
378
403
|
!isDomainSet(config, 'geolocation:')) {
|
|
379
404
|
LeakWarning.warn('proxy_without_geoip');
|
|
380
405
|
}
|
|
@@ -456,21 +481,17 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
456
481
|
else {
|
|
457
482
|
executable_path = launchPath();
|
|
458
483
|
}
|
|
459
|
-
let pwProxy = undefined;
|
|
460
|
-
if (proxy) {
|
|
461
|
-
let proxyUrl = new URL(proxy);
|
|
462
|
-
pwProxy = {
|
|
463
|
-
server: proxyUrl.origin,
|
|
464
|
-
username: proxyUrl.username,
|
|
465
|
-
password: proxyUrl.password,
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
484
|
const out = {
|
|
469
485
|
"executablePath": executable_path,
|
|
470
486
|
"args": args,
|
|
471
487
|
"env": env_vars,
|
|
472
488
|
"firefoxUserPrefs": firefox_user_prefs,
|
|
473
|
-
"proxy":
|
|
489
|
+
"proxy": proxyUrl ? {
|
|
490
|
+
server: proxyUrl.origin,
|
|
491
|
+
username: proxyUrl.username,
|
|
492
|
+
password: proxyUrl.password,
|
|
493
|
+
bypass: typeof proxy === 'string' ? undefined : proxy.bypass,
|
|
494
|
+
} : undefined,
|
|
474
495
|
"headless": headless,
|
|
475
496
|
...launch_options,
|
|
476
497
|
};
|