camoufox-js 0.11.4 → 0.11.5

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/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.11.4",
3
+ "version": "0.11.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": "dist/__main__.js",