headfox-js 0.1.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/LICENSE.md +373 -0
- package/README.md +121 -0
- package/bin/headfox-js.mjs +17 -0
- package/dist/__main__.d.ts +2 -0
- package/dist/__main__.js +131 -0
- package/dist/__version__.d.ts +8 -0
- package/dist/__version__.js +10 -0
- package/dist/addons.d.ts +17 -0
- package/dist/addons.js +74 -0
- package/dist/data-files/territoryInfo.xml +2024 -0
- package/dist/data-files/webgl_data.db +0 -0
- package/dist/exceptions.d.ts +82 -0
- package/dist/exceptions.js +165 -0
- package/dist/fingerprints.d.ts +4 -0
- package/dist/fingerprints.js +82 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/ip.d.ts +25 -0
- package/dist/ip.js +90 -0
- package/dist/locale.d.ts +26 -0
- package/dist/locale.js +285 -0
- package/dist/mappings/browserforge.config.d.ts +47 -0
- package/dist/mappings/browserforge.config.js +72 -0
- package/dist/mappings/fonts.config.d.ts +6 -0
- package/dist/mappings/fonts.config.js +822 -0
- package/dist/mappings/warnings.config.d.ts +16 -0
- package/dist/mappings/warnings.config.js +27 -0
- package/dist/pkgman.d.ts +67 -0
- package/dist/pkgman.js +421 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +24 -0
- package/dist/sync_api.d.ts +10 -0
- package/dist/sync_api.js +35 -0
- package/dist/utils.d.ts +109 -0
- package/dist/utils.js +540 -0
- package/dist/virtdisplay.d.ts +20 -0
- package/dist/virtdisplay.js +123 -0
- package/dist/warnings.d.ts +4 -0
- package/dist/warnings.js +33 -0
- package/dist/webgl/sample.d.ts +19 -0
- package/dist/webgl/sample.js +121 -0
- package/package.json +94 -0
|
Binary file
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export declare class UnsupportedVersion extends Error {
|
|
2
|
+
constructor(message?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class MissingRelease extends Error {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class UnsupportedArchitecture extends Error {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class UnsupportedOS extends Error {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class UnknownProperty extends Error {
|
|
14
|
+
constructor(message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class InvalidPropertyType extends Error {
|
|
17
|
+
constructor(message?: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class InvalidAddonPath extends Error {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class InvalidDebugPort extends Error {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class MissingDebugPort extends Error {
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class LocaleError extends Error {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class InvalidIP extends Error {
|
|
32
|
+
constructor(message?: string);
|
|
33
|
+
}
|
|
34
|
+
export declare class InvalidProxy extends Error {
|
|
35
|
+
constructor(message?: string);
|
|
36
|
+
}
|
|
37
|
+
export declare class UnknownIPLocation extends LocaleError {
|
|
38
|
+
constructor(message?: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class InvalidLocale extends LocaleError {
|
|
41
|
+
constructor(message?: string);
|
|
42
|
+
static invalidInput(locale: string): InvalidLocale;
|
|
43
|
+
}
|
|
44
|
+
export declare class UnknownTerritory extends InvalidLocale {
|
|
45
|
+
constructor(message?: string);
|
|
46
|
+
}
|
|
47
|
+
export declare class UnknownLanguage extends InvalidLocale {
|
|
48
|
+
constructor(message?: string);
|
|
49
|
+
}
|
|
50
|
+
export declare class NotInstalledGeoIPExtra extends Error {
|
|
51
|
+
constructor(message?: string);
|
|
52
|
+
}
|
|
53
|
+
export declare class NonFirefoxFingerprint extends Error {
|
|
54
|
+
constructor(message?: string);
|
|
55
|
+
}
|
|
56
|
+
export declare class InvalidOS extends Error {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
export declare class VirtualDisplayError extends Error {
|
|
60
|
+
constructor(message?: string);
|
|
61
|
+
}
|
|
62
|
+
export declare class CannotFindXvfb extends VirtualDisplayError {
|
|
63
|
+
constructor(message?: string);
|
|
64
|
+
}
|
|
65
|
+
export declare class CannotExecuteXvfb extends VirtualDisplayError {
|
|
66
|
+
constructor(message?: string);
|
|
67
|
+
}
|
|
68
|
+
export declare class VirtualDisplayNotSupported extends VirtualDisplayError {
|
|
69
|
+
constructor(message?: string);
|
|
70
|
+
}
|
|
71
|
+
export declare class HeadfoxNotInstalled extends Error {
|
|
72
|
+
constructor(message?: string);
|
|
73
|
+
}
|
|
74
|
+
export declare class WebGLFingerprintUnavailable extends Error {
|
|
75
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
76
|
+
}
|
|
77
|
+
export declare class CamoufoxNotInstalled extends HeadfoxNotInstalled {
|
|
78
|
+
constructor(message?: string);
|
|
79
|
+
}
|
|
80
|
+
export declare class FileNotFoundError extends Error {
|
|
81
|
+
constructor(message?: string);
|
|
82
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export class UnsupportedVersion extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message ?? "The Headfox executable is outdated.");
|
|
4
|
+
this.name = "UnsupportedVersion";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class MissingRelease extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message ?? "A required GitHub release asset is missing.");
|
|
10
|
+
this.name = "MissingRelease";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class UnsupportedArchitecture extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message ?? "The architecture is not supported.");
|
|
16
|
+
this.name = "UnsupportedArchitecture";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class UnsupportedOS extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message ?? "The OS is not supported.");
|
|
22
|
+
this.name = "UnsupportedOS";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class UnknownProperty extends Error {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message ?? "The property is unknown.");
|
|
28
|
+
this.name = "UnknownProperty";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class InvalidPropertyType extends Error {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message ?? "The property type is invalid.");
|
|
34
|
+
this.name = "InvalidPropertyType";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class InvalidAddonPath extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message ?? "The addon path is invalid.");
|
|
40
|
+
this.name = "InvalidAddonPath";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class InvalidDebugPort extends Error {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message ?? "The debug port is invalid.");
|
|
46
|
+
this.name = "InvalidDebugPort";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class MissingDebugPort extends Error {
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message ?? "The debug port is missing.");
|
|
52
|
+
this.name = "MissingDebugPort";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class LocaleError extends Error {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message ?? "The locale is invalid.");
|
|
58
|
+
this.name = "LocaleError";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export class InvalidIP extends Error {
|
|
62
|
+
constructor(message) {
|
|
63
|
+
super(message ?? "An IP address is invalid.");
|
|
64
|
+
this.name = "InvalidIP";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export class InvalidProxy extends Error {
|
|
68
|
+
constructor(message) {
|
|
69
|
+
super(message ?? "A proxy is invalid.");
|
|
70
|
+
this.name = "InvalidProxy";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export class UnknownIPLocation extends LocaleError {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message ?? "The location of an IP is unknown.");
|
|
76
|
+
this.name = "UnknownIPLocation";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export class InvalidLocale extends LocaleError {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super(message ?? "The locale input is invalid.");
|
|
82
|
+
this.name = "InvalidLocale";
|
|
83
|
+
}
|
|
84
|
+
static invalidInput(locale) {
|
|
85
|
+
return new InvalidLocale(`Invalid locale: '${locale}'. Must be either a region, language, language-region, or language-script-region.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export class UnknownTerritory extends InvalidLocale {
|
|
89
|
+
constructor(message) {
|
|
90
|
+
super(message ?? "The territory is unknown.");
|
|
91
|
+
this.name = "UnknownTerritory";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export class UnknownLanguage extends InvalidLocale {
|
|
95
|
+
constructor(message) {
|
|
96
|
+
super(message ?? "The language is unknown.");
|
|
97
|
+
this.name = "UnknownLanguage";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export class NotInstalledGeoIPExtra extends Error {
|
|
101
|
+
constructor(message) {
|
|
102
|
+
super(message ?? "The geoip2 module is not installed.");
|
|
103
|
+
this.name = "NotInstalledGeoIPExtra";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export class NonFirefoxFingerprint extends Error {
|
|
107
|
+
constructor(message) {
|
|
108
|
+
super(message ?? "A passed Browserforge fingerprint is invalid.");
|
|
109
|
+
this.name = "NonFirefoxFingerprint";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class InvalidOS extends Error {
|
|
113
|
+
constructor(message) {
|
|
114
|
+
super(message ?? "The target OS is invalid.");
|
|
115
|
+
this.name = "InvalidOS";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export class VirtualDisplayError extends Error {
|
|
119
|
+
constructor(message) {
|
|
120
|
+
super(message ?? "There is an error with the virtual display.");
|
|
121
|
+
this.name = "VirtualDisplayError";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export class CannotFindXvfb extends VirtualDisplayError {
|
|
125
|
+
constructor(message) {
|
|
126
|
+
super(message ?? "Xvfb cannot be found.");
|
|
127
|
+
this.name = "CannotFindXvfb";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export class CannotExecuteXvfb extends VirtualDisplayError {
|
|
131
|
+
constructor(message) {
|
|
132
|
+
super(message ?? "Xvfb cannot be executed.");
|
|
133
|
+
this.name = "CannotExecuteXvfb";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export class VirtualDisplayNotSupported extends VirtualDisplayError {
|
|
137
|
+
constructor(message) {
|
|
138
|
+
super(message ?? "The user tried to use a virtual display on a non-Linux OS.");
|
|
139
|
+
this.name = "VirtualDisplayNotSupported";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export class HeadfoxNotInstalled extends Error {
|
|
143
|
+
constructor(message) {
|
|
144
|
+
super(message ?? "Headfox is not installed.");
|
|
145
|
+
this.name = "HeadfoxNotInstalled";
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export class WebGLFingerprintUnavailable extends Error {
|
|
149
|
+
constructor(message, options) {
|
|
150
|
+
super(message ?? "WebGL fingerprint sampling is unavailable in this runtime.", options);
|
|
151
|
+
this.name = "WebGLFingerprintUnavailable";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export class CamoufoxNotInstalled extends HeadfoxNotInstalled {
|
|
155
|
+
constructor(message) {
|
|
156
|
+
super(message ?? "Camoufox is not installed.");
|
|
157
|
+
this.name = "CamoufoxNotInstalled";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export class FileNotFoundError extends Error {
|
|
161
|
+
constructor(message) {
|
|
162
|
+
super(message ?? "File couldn't be found.");
|
|
163
|
+
this.name = "FileNotFoundError";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Fingerprint, type FingerprintGeneratorOptions } from "fingerprint-generator";
|
|
2
|
+
export declare const SUPPORTED_OS: readonly ["linux", "macos", "windows"];
|
|
3
|
+
export declare function fromBrowserforge(fingerprint: Fingerprint, ffVersion?: string): Record<string, any>;
|
|
4
|
+
export declare function generateFingerprint(window?: [number, number], config?: Partial<FingerprintGeneratorOptions>): Fingerprint;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { FingerprintGenerator, } from "fingerprint-generator";
|
|
2
|
+
import BROWSERFORGE_DATA from "./mappings/browserforge.config.js";
|
|
3
|
+
export const SUPPORTED_OS = ["linux", "macos", "windows"];
|
|
4
|
+
const FP_GENERATOR = new FingerprintGenerator({
|
|
5
|
+
browsers: ["firefox"],
|
|
6
|
+
operatingSystems: SUPPORTED_OS,
|
|
7
|
+
});
|
|
8
|
+
function randrange(min, max) {
|
|
9
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
10
|
+
}
|
|
11
|
+
function _castToProperties(camoufoxData, castEnum, bfDict, ffVersion) {
|
|
12
|
+
for (let [key, data] of Object.entries(bfDict)) {
|
|
13
|
+
if (!data)
|
|
14
|
+
continue;
|
|
15
|
+
const typeKey = castEnum[key];
|
|
16
|
+
if (!typeKey)
|
|
17
|
+
continue;
|
|
18
|
+
if (typeof data === "object" && !Array.isArray(data)) {
|
|
19
|
+
_castToProperties(camoufoxData, typeKey, data, ffVersion);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (typeKey.startsWith("screen.") && typeof data === "number" && data < 0) {
|
|
23
|
+
data = 0;
|
|
24
|
+
}
|
|
25
|
+
if (ffVersion && typeof data === "string") {
|
|
26
|
+
data = data.replaceAll(/(?<!\d)(1[0-9]{2})(\.0)(?!\d)/gi, `${ffVersion}$2`);
|
|
27
|
+
}
|
|
28
|
+
camoufoxData[typeKey] = data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function handleScreenXY(camoufoxData, fpScreen) {
|
|
32
|
+
if ("window.screenY" in camoufoxData)
|
|
33
|
+
return;
|
|
34
|
+
const screenX = fpScreen.screenX;
|
|
35
|
+
if (!screenX) {
|
|
36
|
+
camoufoxData["window.screenX"] = 0;
|
|
37
|
+
camoufoxData["window.screenY"] = 0;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (screenX >= -50 && screenX <= 50) {
|
|
41
|
+
camoufoxData["window.screenY"] = screenX;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const screenY = fpScreen.availHeight - fpScreen.outerHeight;
|
|
45
|
+
if (screenY === 0) {
|
|
46
|
+
camoufoxData["window.screenY"] = 0;
|
|
47
|
+
}
|
|
48
|
+
else if (screenY > 0) {
|
|
49
|
+
camoufoxData["window.screenY"] = randrange(0, screenY);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
camoufoxData["window.screenY"] = randrange(screenY, 0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function fromBrowserforge(fingerprint, ffVersion) {
|
|
56
|
+
const camoufoxData = {};
|
|
57
|
+
_castToProperties(camoufoxData, BROWSERFORGE_DATA, { ...fingerprint }, ffVersion);
|
|
58
|
+
handleScreenXY(camoufoxData, fingerprint.screen);
|
|
59
|
+
return camoufoxData;
|
|
60
|
+
}
|
|
61
|
+
function handleWindowSize(fp, outerWidth, outerHeight) {
|
|
62
|
+
const sc = { ...fp.screen, screenY: undefined };
|
|
63
|
+
sc.screenX += Math.floor((sc.width - outerWidth) / 2);
|
|
64
|
+
sc.screenY = Math.floor((sc.height - outerHeight) / 2);
|
|
65
|
+
if (sc.innerWidth) {
|
|
66
|
+
sc.innerWidth = Math.max(outerWidth - sc.outerWidth + sc.innerWidth, 0);
|
|
67
|
+
}
|
|
68
|
+
if (sc.innerHeight) {
|
|
69
|
+
sc.innerHeight = Math.max(outerHeight - sc.outerHeight + sc.innerHeight, 0);
|
|
70
|
+
}
|
|
71
|
+
sc.outerWidth = outerWidth;
|
|
72
|
+
sc.outerHeight = outerHeight;
|
|
73
|
+
fp.screen = sc;
|
|
74
|
+
}
|
|
75
|
+
export function generateFingerprint(window, config) {
|
|
76
|
+
if (window) {
|
|
77
|
+
const { fingerprint } = FP_GENERATOR.getFingerprint(config);
|
|
78
|
+
handleWindowSize(fingerprint, window[0], window[1]);
|
|
79
|
+
return fingerprint;
|
|
80
|
+
}
|
|
81
|
+
return FP_GENERATOR.getFingerprint(config).fingerprint;
|
|
82
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CamoufoxFetcher, camoufoxPath, ensureBrowserInstalled, getInstalledBrowserDir, HeadfoxFetcher, headfoxPath, installedVerStr, isBrowserInstalled, launchPath, } from "./pkgman.js";
|
|
2
|
+
export { launchHeadfoxServer, launchServer } from "./server.js";
|
|
3
|
+
export { Camoufox, Headfox, launchWithHeadfox, NewBrowser, } from "./sync_api.js";
|
|
4
|
+
export { type LaunchOptions, launchOptions } from "./utils.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CamoufoxFetcher, camoufoxPath, ensureBrowserInstalled, getInstalledBrowserDir, HeadfoxFetcher, headfoxPath, installedVerStr, isBrowserInstalled, launchPath, } from "./pkgman.js";
|
|
2
|
+
export { launchHeadfoxServer, launchServer } from "./server.js";
|
|
3
|
+
export { Camoufox, Headfox, launchWithHeadfox, NewBrowser, } from "./sync_api.js";
|
|
4
|
+
export { launchOptions } from "./utils.js";
|
package/dist/ip.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class InvalidIP extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class InvalidProxy extends Error {
|
|
4
|
+
}
|
|
5
|
+
export interface Proxy {
|
|
6
|
+
server: string;
|
|
7
|
+
username?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
bypass?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const ProxyHelper: {
|
|
12
|
+
readonly parseServer: (server: string) => {
|
|
13
|
+
schema: string;
|
|
14
|
+
url: string;
|
|
15
|
+
port?: string;
|
|
16
|
+
};
|
|
17
|
+
readonly asString: (proxy: Proxy) => string;
|
|
18
|
+
readonly asAxiosProxy: (proxyString: string) => {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare function validIPv4(ip: string | false): boolean;
|
|
23
|
+
export declare function validIPv6(ip: string | false): boolean;
|
|
24
|
+
export declare function validateIP(ip: string): void;
|
|
25
|
+
export declare function publicIP(proxy?: string): Promise<string>;
|
package/dist/ip.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Impit } from "impit";
|
|
2
|
+
export class InvalidIP extends Error {
|
|
3
|
+
}
|
|
4
|
+
export class InvalidProxy extends Error {
|
|
5
|
+
}
|
|
6
|
+
export const ProxyHelper = {
|
|
7
|
+
parseServer(server) {
|
|
8
|
+
const proxyMatch = server.match(/^(?:(\w+):\/\/)?(.*?)(?::(\d+))?$/);
|
|
9
|
+
if (!proxyMatch) {
|
|
10
|
+
throw new InvalidProxy(`Invalid proxy server: ${server}`);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
schema: proxyMatch[1] || "http",
|
|
14
|
+
url: proxyMatch[2],
|
|
15
|
+
port: proxyMatch[3],
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
asString(proxy) {
|
|
19
|
+
const { schema, url, port } = ProxyHelper.parseServer(proxy.server);
|
|
20
|
+
let result = `${schema}://`;
|
|
21
|
+
if (proxy.username) {
|
|
22
|
+
result += proxy.username;
|
|
23
|
+
if (proxy.password) {
|
|
24
|
+
result += `:${proxy.password}`;
|
|
25
|
+
}
|
|
26
|
+
result += "@";
|
|
27
|
+
}
|
|
28
|
+
result += url;
|
|
29
|
+
if (port) {
|
|
30
|
+
result += `:${port}`;
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
},
|
|
34
|
+
asAxiosProxy(proxyString) {
|
|
35
|
+
return {
|
|
36
|
+
http: proxyString,
|
|
37
|
+
https: proxyString,
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
export function validIPv4(ip) {
|
|
42
|
+
if (!ip) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(ip);
|
|
46
|
+
}
|
|
47
|
+
export function validIPv6(ip) {
|
|
48
|
+
if (!ip) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return /^(([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4})$/.test(ip);
|
|
52
|
+
}
|
|
53
|
+
export function validateIP(ip) {
|
|
54
|
+
if (!validIPv4(ip) && !validIPv6(ip)) {
|
|
55
|
+
throw new InvalidIP(`Invalid IP address: ${ip}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export async function publicIP(proxy) {
|
|
59
|
+
const URLS = [
|
|
60
|
+
"https://api.ipify.org",
|
|
61
|
+
"https://checkip.amazonaws.com",
|
|
62
|
+
"https://ipinfo.io/ip",
|
|
63
|
+
"https://icanhazip.com",
|
|
64
|
+
"https://ifconfig.co/ip",
|
|
65
|
+
"https://ipecho.net/plain",
|
|
66
|
+
];
|
|
67
|
+
const errors = [];
|
|
68
|
+
for (const url of URLS) {
|
|
69
|
+
try {
|
|
70
|
+
const impit = new Impit({
|
|
71
|
+
proxyUrl: proxy,
|
|
72
|
+
timeout: 5000,
|
|
73
|
+
});
|
|
74
|
+
const response = await impit.fetch(url);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const ip = (await response.text()).trim();
|
|
79
|
+
validateIP(ip);
|
|
80
|
+
return ip;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
errors.push(error);
|
|
84
|
+
if (process.env.HEADFOX_DEBUG || process.env.CAMOUFOX_DEBUG) {
|
|
85
|
+
console.warn(new InvalidProxy(`headfox-js(warn): Failed to fetch public proxy IP from ${url}, retrying with another URL...`, { cause: error }));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw new InvalidIP("Failed to get a public proxy IP address from any API endpoint.", { cause: errors });
|
|
90
|
+
}
|
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const ALLOW_GEOIP = true;
|
|
2
|
+
declare class Locale {
|
|
3
|
+
language: string;
|
|
4
|
+
region?: string | undefined;
|
|
5
|
+
script?: string | undefined;
|
|
6
|
+
constructor(language: string, region?: string | undefined, script?: string | undefined);
|
|
7
|
+
asString(): string;
|
|
8
|
+
asConfig(): Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
declare class Geolocation {
|
|
11
|
+
locale: Locale;
|
|
12
|
+
longitude: number;
|
|
13
|
+
latitude: number;
|
|
14
|
+
timezone: string;
|
|
15
|
+
accuracy?: number | undefined;
|
|
16
|
+
constructor(locale: Locale, longitude: number, latitude: number, timezone: string, accuracy?: number | undefined);
|
|
17
|
+
asConfig(): Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
export declare function normalizeLocale(locale: string): Locale;
|
|
20
|
+
export declare function handleLocale(locale: string, ignoreRegion?: boolean): Locale;
|
|
21
|
+
export declare function handleLocales(locales: string | string[], config: Record<string, any>): void;
|
|
22
|
+
export declare function geoipAllowed(): void;
|
|
23
|
+
export declare function downloadMMDB(): Promise<void>;
|
|
24
|
+
export declare function removeMMDB(): void;
|
|
25
|
+
export declare function getGeolocation(ip: string): Promise<Geolocation>;
|
|
26
|
+
export {};
|