camoufox-js 0.11.4 → 0.12.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/__main__.js +2 -2
- package/dist/locale.js +22 -2
- package/dist/pkgman.js +1 -1
- package/dist/sync_api.js +8 -1
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +49 -0
- package/package.json +4 -4
package/dist/__main__.js
CHANGED
|
@@ -72,9 +72,9 @@ program.command("fetch").action(async () => {
|
|
|
72
72
|
const updater = await CamoufoxUpdate.create();
|
|
73
73
|
await updater.update();
|
|
74
74
|
if (ALLOW_GEOIP) {
|
|
75
|
-
downloadMMDB();
|
|
75
|
+
await downloadMMDB();
|
|
76
76
|
}
|
|
77
|
-
maybeDownloadAddons(DefaultAddons);
|
|
77
|
+
await maybeDownloadAddons(DefaultAddons);
|
|
78
78
|
});
|
|
79
79
|
program.command("remove").action(async () => {
|
|
80
80
|
const updater = await CamoufoxUpdate.create();
|
package/dist/locale.js
CHANGED
|
@@ -154,8 +154,28 @@ export async function downloadMMDB() {
|
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
const assetUrl = await new MaxMindDownloader(MMDB_REPO).getAsset();
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
// Download into a temporary file and only move it into place once the
|
|
158
|
+
// download finished. Writing straight to MMDB_FILE leaves an empty or
|
|
159
|
+
// truncated database behind when the download fails, and getGeolocation()
|
|
160
|
+
// only checks that the file exists - so every later run would pick up the
|
|
161
|
+
// corrupt file and fail until it is removed by hand.
|
|
162
|
+
const tempFile = `${MMDB_FILE}.${process.pid}.download`;
|
|
163
|
+
const fileStream = fs.createWriteStream(tempFile);
|
|
164
|
+
try {
|
|
165
|
+
await webdl(assetUrl, "Downloading GeoIP database", true, fileStream);
|
|
166
|
+
// Flush and close before renaming, otherwise the database can be opened
|
|
167
|
+
// while the last chunks are still buffered.
|
|
168
|
+
await new Promise((resolve, reject) => fileStream.close((err) => (err ? reject(err) : resolve())));
|
|
169
|
+
fs.renameSync(tempFile, MMDB_FILE);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
// Close before removing: Windows can't unlink a file with an open handle.
|
|
173
|
+
if (!fileStream.closed) {
|
|
174
|
+
await new Promise((resolve) => fileStream.close(() => resolve()));
|
|
175
|
+
}
|
|
176
|
+
fs.rmSync(tempFile, { force: true });
|
|
177
|
+
throw e;
|
|
178
|
+
}
|
|
159
179
|
}
|
|
160
180
|
export function removeMMDB() {
|
|
161
181
|
if (!fs.existsSync(MMDB_FILE)) {
|
package/dist/pkgman.js
CHANGED
|
@@ -388,7 +388,7 @@ export async function unzip(zipFile, extractPath, desc, bar = true) {
|
|
|
388
388
|
if (bar) {
|
|
389
389
|
console.log(`Extracting ${entry.entryName}`);
|
|
390
390
|
}
|
|
391
|
-
zip.extractEntryTo(entry, extractPath,
|
|
391
|
+
zip.extractEntryTo(entry, extractPath, true, true);
|
|
392
392
|
}
|
|
393
393
|
if (bar) {
|
|
394
394
|
console.log("Extraction complete.");
|
package/dist/sync_api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { firefox, } from "playwright-core";
|
|
2
|
-
import { launchOptions, syncAttachVD } from "./utils.js";
|
|
2
|
+
import { attachNoViewportDefault, launchOptions, spoofsWindowDimensions, syncAttachVD, } from "./utils.js";
|
|
3
3
|
import { VirtualDisplay } from "./virtdisplay.js";
|
|
4
4
|
export async function Camoufox(launch_options = {}) {
|
|
5
5
|
const { headless, user_data_dir, ...launchOptions } = launch_options;
|
|
@@ -20,10 +20,17 @@ export async function NewBrowser(playwright, headless = false, fromOptions = {},
|
|
|
20
20
|
headless: normalizedHeadless,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
const noViewportDefault = spoofsWindowDimensions(fromOptions);
|
|
23
24
|
if (typeof userDataDir === "string") {
|
|
25
|
+
if (noViewportDefault && !("viewport" in fromOptions)) {
|
|
26
|
+
fromOptions = { ...fromOptions, viewport: null };
|
|
27
|
+
}
|
|
24
28
|
const context = await playwright.launchPersistentContext(userDataDir, fromOptions);
|
|
25
29
|
return syncAttachVD(context, virtualDisplay);
|
|
26
30
|
}
|
|
27
31
|
const browser = await playwright.launch(fromOptions);
|
|
32
|
+
if (noViewportDefault) {
|
|
33
|
+
attachNoViewportDefault(browser);
|
|
34
|
+
}
|
|
28
35
|
return syncAttachVD(browser, virtualDisplay);
|
|
29
36
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -6,6 +6,25 @@ import { SUPPORTED_OS } from "./fingerprints.js";
|
|
|
6
6
|
import type { VirtualDisplay } from "./virtdisplay.js";
|
|
7
7
|
type Screen = FingerprintGeneratorOptions["screen"];
|
|
8
8
|
export declare function getAsBooleanFromENV(name: string, defaultValue?: boolean | undefined): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the CAMOU_CONFIG in a set of launch options spoofs any window
|
|
11
|
+
* dimension. The config is chunked across CAMOU_CONFIG_<n> env vars, so
|
|
12
|
+
* reassemble it in index order before looking.
|
|
13
|
+
*/
|
|
14
|
+
export declare function spoofsWindowDimensions(fromOptions: Record<string, any>): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Defaults newPage()/newContext() to `viewport: null`.
|
|
17
|
+
*
|
|
18
|
+
* Playwright applies a 1280x720 viewport by default, which makes Juggler ask
|
|
19
|
+
* the content window to become 1280x720. When Camoufox is pinning the window to
|
|
20
|
+
* a spoofed size, that request can never be satisfied, so the page reports the
|
|
21
|
+
* Playwright viewport instead of the spoofed dimensions (and a second
|
|
22
|
+
* newPage() can hang - daijro/camoufox#666).
|
|
23
|
+
*
|
|
24
|
+
* Without a viewport, Juggler measures the window instead of resizing it.
|
|
25
|
+
* An explicit viewport from the caller always wins.
|
|
26
|
+
*/
|
|
27
|
+
export declare function attachNoViewportDefault<T>(target: T): T;
|
|
9
28
|
export declare function syncAttachVD(browser: any, virtualDisplay?: VirtualDisplay | null): any;
|
|
10
29
|
export interface LaunchOptions {
|
|
11
30
|
/** Operating system to use for the fingerprint generation.
|
package/dist/utils.js
CHANGED
|
@@ -213,6 +213,55 @@ function warnManualConfig(config) {
|
|
|
213
213
|
LeakWarning.warn("viewport", false);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
+
const WINDOW_DIM_KEYS = [
|
|
217
|
+
"window.outerWidth",
|
|
218
|
+
"window.outerHeight",
|
|
219
|
+
"window.innerWidth",
|
|
220
|
+
"window.innerHeight",
|
|
221
|
+
"document.body.clientWidth",
|
|
222
|
+
"document.body.clientHeight",
|
|
223
|
+
];
|
|
224
|
+
/**
|
|
225
|
+
* Whether the CAMOU_CONFIG in a set of launch options spoofs any window
|
|
226
|
+
* dimension. The config is chunked across CAMOU_CONFIG_<n> env vars, so
|
|
227
|
+
* reassemble it in index order before looking.
|
|
228
|
+
*/
|
|
229
|
+
export function spoofsWindowDimensions(fromOptions) {
|
|
230
|
+
const env = fromOptions.env ?? {};
|
|
231
|
+
const chunks = Object.entries(env)
|
|
232
|
+
.filter(([key]) => key.startsWith("CAMOU_CONFIG_"))
|
|
233
|
+
.map(([key, value]) => [Number(key.split("_").pop()), value])
|
|
234
|
+
.sort(([a], [b]) => a - b);
|
|
235
|
+
if (chunks.length === 0) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const blob = chunks.map(([, value]) => value).join("");
|
|
239
|
+
return WINDOW_DIM_KEYS.some((key) => blob.includes(key));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Defaults newPage()/newContext() to `viewport: null`.
|
|
243
|
+
*
|
|
244
|
+
* Playwright applies a 1280x720 viewport by default, which makes Juggler ask
|
|
245
|
+
* the content window to become 1280x720. When Camoufox is pinning the window to
|
|
246
|
+
* a spoofed size, that request can never be satisfied, so the page reports the
|
|
247
|
+
* Playwright viewport instead of the spoofed dimensions (and a second
|
|
248
|
+
* newPage() can hang - daijro/camoufox#666).
|
|
249
|
+
*
|
|
250
|
+
* Without a viewport, Juggler measures the window instead of resizing it.
|
|
251
|
+
* An explicit viewport from the caller always wins.
|
|
252
|
+
*/
|
|
253
|
+
export function attachNoViewportDefault(target) {
|
|
254
|
+
for (const name of ["newPage", "newContext"]) {
|
|
255
|
+
const original = target[name];
|
|
256
|
+
if (typeof original !== "function") {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
target[name] = (options, ...rest) => original.call(target, options && "viewport" in options
|
|
260
|
+
? options
|
|
261
|
+
: { ...options, viewport: null }, ...rest);
|
|
262
|
+
}
|
|
263
|
+
return target;
|
|
264
|
+
}
|
|
216
265
|
async function _asyncAttachVD(browser, virtualDisplay) {
|
|
217
266
|
if (!virtualDisplay) {
|
|
218
267
|
return browser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "camoufox-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"bin": "dist/__main__.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"language-tags": "^2.0.1",
|
|
34
34
|
"maxmind": "^5.0.0",
|
|
35
35
|
"pretty-bytes": "^7.1.0",
|
|
36
|
-
"ua-parser-js": "^2.0.
|
|
36
|
+
"ua-parser-js": "^2.0.10",
|
|
37
37
|
"xml2js": "^0.6.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"@types/language-tags": "^1.0.4",
|
|
45
45
|
"@types/node": "^24.0.0",
|
|
46
46
|
"@types/xml2js": "^0.4.14",
|
|
47
|
-
"playwright-core": "
|
|
47
|
+
"playwright-core": "<1.61.0",
|
|
48
48
|
"rimraf": "^6.0.1",
|
|
49
49
|
"typescript": "^5.8.3",
|
|
50
50
|
"vitest": "^4.0.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"playwright-core": "
|
|
53
|
+
"playwright-core": "<1.61.0"
|
|
54
54
|
},
|
|
55
55
|
"devEngines": {
|
|
56
56
|
"packageManager": {
|