camoucore 0.3.0 → 0.6.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 +4 -3
- package/dist/camoufox/__main__.d.ts +10 -0
- package/dist/camoufox/__main__.js +1175 -0
- package/dist/camoufox/__version__.d.ts +31 -0
- package/dist/camoufox/__version__.js +32 -0
- package/dist/camoufox/_humanize_playwright.d.ts +54 -0
- package/dist/camoufox/_humanize_playwright.js +429 -0
- package/dist/camoufox/addons.d.ts +21 -0
- package/dist/camoufox/addons.js +56 -0
- package/dist/camoufox/async_api.d.ts +9 -0
- package/dist/camoufox/async_api.js +9 -0
- package/dist/camoufox/browser-pin.d.ts +46 -0
- package/dist/camoufox/browser-pin.js +96 -0
- package/dist/camoufox/cli.d.ts +7 -0
- package/dist/camoufox/cli.js +20 -0
- package/dist/camoufox/coherence.d.ts +141 -0
- package/dist/camoufox/coherence.js +708 -0
- package/dist/camoufox/data-files/browser-pin.json +7 -0
- package/dist/camoufox/data-files/essential-fonts.json +5 -0
- package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
- package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
- package/dist/camoufox/data-files/font-bases.json +1887 -0
- package/dist/camoufox/data-files/font-groups.json +716 -0
- package/dist/camoufox/data-files/fonts.json +240 -0
- package/dist/camoufox/data-files/fpgen.yml +44 -0
- package/dist/camoufox/data-files/launcher-constants.json +66 -0
- package/dist/camoufox/data-files/media-devices.json +148 -0
- package/dist/camoufox/data-files/repos.yml +40 -0
- package/dist/camoufox/data-files/voice-manifests.json +1864 -0
- package/dist/camoufox/data-files/voice-uris.json +188 -0
- package/dist/camoufox/data-files/warnings.yml +132 -0
- package/dist/camoufox/display_profile.d.ts +17 -0
- package/dist/camoufox/display_profile.js +72 -0
- package/dist/camoufox/driver_defaults.d.ts +25 -0
- package/dist/camoufox/driver_defaults.js +114 -0
- package/dist/camoufox/exceptions.d.ts +78 -0
- package/dist/camoufox/exceptions.js +135 -0
- package/dist/camoufox/fingerprints.d.ts +341 -0
- package/dist/camoufox/fingerprints.js +1682 -0
- package/dist/camoufox/gpudisplay.d.ts +158 -0
- package/dist/camoufox/gpudisplay.js +695 -0
- package/dist/camoufox/host_rendering.d.ts +38 -0
- package/dist/camoufox/host_rendering.js +180 -0
- package/dist/camoufox/humanize.d.ts +89 -0
- package/dist/camoufox/humanize.js +143 -0
- package/dist/camoufox/index.d.ts +21 -0
- package/dist/camoufox/index.js +21 -0
- package/dist/camoufox/ip.d.ts +45 -0
- package/dist/camoufox/ip.js +114 -0
- package/dist/camoufox/multiversion.d.ts +131 -0
- package/dist/camoufox/multiversion.js +489 -0
- package/dist/camoufox/node-floor.d.ts +5 -0
- package/dist/camoufox/node-floor.js +17 -0
- package/dist/camoufox/paths.d.ts +45 -0
- package/dist/camoufox/paths.js +59 -0
- package/dist/camoufox/pkgman.d.ts +331 -0
- package/dist/camoufox/pkgman.js +972 -0
- package/dist/camoufox/product.d.ts +8 -0
- package/dist/camoufox/product.js +8 -0
- package/dist/camoufox/pycompat.d.ts +97 -0
- package/dist/camoufox/pycompat.js +458 -0
- package/dist/camoufox/server.d.ts +36 -0
- package/dist/camoufox/server.js +82 -0
- package/dist/camoufox/sync_api.d.ts +77 -0
- package/dist/camoufox/sync_api.js +194 -0
- package/dist/camoufox/utils.d.ts +515 -0
- package/dist/camoufox/utils.js +1995 -0
- package/dist/camoufox/warnings.d.ts +16 -0
- package/dist/camoufox/warnings.js +65 -0
- package/dist/camoufox/webgl.d.ts +52 -0
- package/dist/camoufox/webgl.js +264 -0
- package/dist/camouwolf/__main__.d.ts +10 -0
- package/dist/camouwolf/__main__.js +1180 -0
- package/dist/camouwolf/__version__.d.ts +31 -0
- package/dist/camouwolf/__version__.js +32 -0
- package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
- package/dist/camouwolf/_humanize_playwright.js +427 -0
- package/dist/camouwolf/addons.d.ts +42 -0
- package/dist/camouwolf/addons.js +113 -0
- package/dist/camouwolf/async_api.d.ts +9 -0
- package/dist/camouwolf/async_api.js +9 -0
- package/dist/camouwolf/browser-pin.d.ts +46 -0
- package/dist/camouwolf/browser-pin.js +96 -0
- package/dist/camouwolf/cli.d.ts +7 -0
- package/dist/camouwolf/cli.js +20 -0
- package/dist/camouwolf/clienthints.d.ts +61 -0
- package/dist/camouwolf/clienthints.js +176 -0
- package/dist/camouwolf/coherence.d.ts +152 -0
- package/dist/camouwolf/coherence.js +554 -0
- package/dist/camouwolf/data-files/browser-pin.json +7 -0
- package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
- package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
- package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
- package/dist/camouwolf/data-files/data/properties.json +321 -0
- package/dist/camouwolf/data-files/data/system-colors.json +35 -0
- package/dist/camouwolf/data-files/data/ubo.json +6 -0
- package/dist/camouwolf/data-files/fpgen.yml +41 -0
- package/dist/camouwolf/data-files/launcher-constants.json +26 -0
- package/dist/camouwolf/data-files/repos.yml +23 -0
- package/dist/camouwolf/data-files/warnings.yml +96 -0
- package/dist/camouwolf/driver_defaults.d.ts +25 -0
- package/dist/camouwolf/driver_defaults.js +114 -0
- package/dist/camouwolf/exceptions.d.ts +95 -0
- package/dist/camouwolf/exceptions.js +150 -0
- package/dist/camouwolf/fingerprints.d.ts +227 -0
- package/dist/camouwolf/fingerprints.js +753 -0
- package/dist/camouwolf/gpudisplay.d.ts +171 -0
- package/dist/camouwolf/gpudisplay.js +711 -0
- package/dist/camouwolf/host_rendering.d.ts +18 -0
- package/dist/camouwolf/host_rendering.js +114 -0
- package/dist/camouwolf/humanize.d.ts +84 -0
- package/dist/camouwolf/humanize.js +128 -0
- package/dist/camouwolf/index.d.ts +22 -0
- package/dist/camouwolf/index.js +21 -0
- package/dist/camouwolf/multiversion.d.ts +131 -0
- package/dist/camouwolf/multiversion.js +491 -0
- package/dist/camouwolf/node-floor.d.ts +5 -0
- package/dist/camouwolf/node-floor.js +17 -0
- package/dist/camouwolf/paths.d.ts +34 -0
- package/dist/camouwolf/paths.js +58 -0
- package/dist/camouwolf/pkgman.d.ts +331 -0
- package/dist/camouwolf/pkgman.js +972 -0
- package/dist/camouwolf/product.d.ts +3 -0
- package/dist/camouwolf/product.js +3 -0
- package/dist/camouwolf/pycompat.d.ts +92 -0
- package/dist/camouwolf/pycompat.js +461 -0
- package/dist/camouwolf/server.d.ts +36 -0
- package/dist/camouwolf/server.js +81 -0
- package/dist/camouwolf/switches.d.ts +77 -0
- package/dist/camouwolf/switches.js +222 -0
- package/dist/camouwolf/sync_api.d.ts +84 -0
- package/dist/camouwolf/sync_api.js +173 -0
- package/dist/camouwolf/utils.d.ts +644 -0
- package/dist/camouwolf/utils.js +2057 -0
- package/dist/camouwolf/warnings.d.ts +14 -0
- package/dist/camouwolf/warnings.js +59 -0
- package/dist/camouwolf/webgl.d.ts +41 -0
- package/dist/camouwolf/webgl.js +198 -0
- package/dist/data.d.ts +1 -1
- package/dist/data.js +3 -3
- package/dist/download.js +1 -1
- package/dist/exceptions.d.ts +1 -1
- package/dist/exceptions.js +1 -1
- package/dist/geolocation.js +1 -1
- package/dist/host.js +1 -1
- package/dist/ip.js +1 -1
- package/dist/locales.js +1 -1
- package/dist/mcp/cli.d.ts +15 -0
- package/dist/mcp/cli.js +108 -0
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/main.d.ts +2 -0
- package/dist/mcp/main.js +8 -0
- package/dist/mcp/secrets.d.ts +50 -0
- package/dist/mcp/secrets.js +193 -0
- package/dist/mcp/server.d.ts +48 -0
- package/dist/mcp/server.js +653 -0
- package/dist/mcp/tree.d.ts +10 -0
- package/dist/mcp/tree.js +36 -0
- package/dist/passthrough.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/settings.js +1 -1
- package/dist/telemetry.d.ts +0 -1
- package/dist/telemetry.js +5 -4
- package/dist/virtdisplay.d.ts +1 -1
- package/dist/virtdisplay.js +1 -1
- package/dist/warnings.js +1 -1
- package/package.json +57 -13
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camouwolf version constants.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript twin of python/camoucore/src/camoucore/camouwolf/__version__.py.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CONSTRAINTS {
|
|
7
|
+
/**
|
|
8
|
+
* The minimum and maximum supported versions of the Camouwolf browser.
|
|
9
|
+
*/
|
|
10
|
+
static readonly MIN_VERSION: string;
|
|
11
|
+
static readonly MAX_VERSION: string;
|
|
12
|
+
/**
|
|
13
|
+
* [playwrightVersion, browserBuild]: from that Playwright on, the browser must
|
|
14
|
+
* be at least that build. Empty: Camouwolf is driven over CDP, which no
|
|
15
|
+
* Playwright release has yet outgrown for a Camouwolf build.
|
|
16
|
+
*/
|
|
17
|
+
static readonly PLAYWRIGHT_BROWSER_FLOORS: ReadonlyArray<readonly [readonly number[], string]>;
|
|
18
|
+
/**
|
|
19
|
+
* The browser interface built from this tree. Every browser release
|
|
20
|
+
* declares it in its manifest.json (ci/release.py reads it from the Python
|
|
21
|
+
* twin), and this library accepts browsers from MIN_INTERFACE up to it.
|
|
22
|
+
* Raise it when a browser change would break released libraries; raise
|
|
23
|
+
* MIN_INTERFACE when this library can no longer drive older browsers.
|
|
24
|
+
* Releases from before manifests carried the field are interface 1.
|
|
25
|
+
*/
|
|
26
|
+
static readonly INTERFACE: number;
|
|
27
|
+
static readonly MIN_INTERFACE: number;
|
|
28
|
+
}
|
|
29
|
+
/** Version of this launcher library. Kept in step with package.json and
|
|
30
|
+
* pythonlib's pyproject.toml. */
|
|
31
|
+
export declare const LIBRARY_VERSION = "0.6.1";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camouwolf version constants.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript twin of python/camoucore/src/camoucore/camouwolf/__version__.py.
|
|
5
|
+
*/
|
|
6
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: mirrors the Python twin's CONSTRAINTS class so both launchers read the same
|
|
7
|
+
export class CONSTRAINTS {
|
|
8
|
+
/**
|
|
9
|
+
* The minimum and maximum supported versions of the Camouwolf browser.
|
|
10
|
+
*/
|
|
11
|
+
static MIN_VERSION = "alpha.1";
|
|
12
|
+
static MAX_VERSION = "1";
|
|
13
|
+
/**
|
|
14
|
+
* [playwrightVersion, browserBuild]: from that Playwright on, the browser must
|
|
15
|
+
* be at least that build. Empty: Camouwolf is driven over CDP, which no
|
|
16
|
+
* Playwright release has yet outgrown for a Camouwolf build.
|
|
17
|
+
*/
|
|
18
|
+
static PLAYWRIGHT_BROWSER_FLOORS = [];
|
|
19
|
+
/**
|
|
20
|
+
* The browser interface built from this tree. Every browser release
|
|
21
|
+
* declares it in its manifest.json (ci/release.py reads it from the Python
|
|
22
|
+
* twin), and this library accepts browsers from MIN_INTERFACE up to it.
|
|
23
|
+
* Raise it when a browser change would break released libraries; raise
|
|
24
|
+
* MIN_INTERFACE when this library can no longer drive older browsers.
|
|
25
|
+
* Releases from before manifests carried the field are interface 1.
|
|
26
|
+
*/
|
|
27
|
+
static INTERFACE = 1;
|
|
28
|
+
static MIN_INTERFACE = 1;
|
|
29
|
+
}
|
|
30
|
+
/** Version of this launcher library. Kept in step with package.json and
|
|
31
|
+
* pythonlib's pyproject.toml. */
|
|
32
|
+
export const LIBRARY_VERSION = "0.6.1";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* myuri's smart actions on Playwright pages. The TypeScript twin of
|
|
3
|
+
* python/camoucore/src/camoucore/camouwolf/_humanize_playwright.py; both are held to the sequence
|
|
4
|
+
* in browser/tests/humanize/sequence.json.
|
|
5
|
+
*
|
|
6
|
+
* Each page of the browser (or persistent context) a humanize setting is
|
|
7
|
+
* attached to gets one myuri `Actions`. It owns the timing and motion of the
|
|
8
|
+
* page's input and the decisions around a click: scroll the element into
|
|
9
|
+
* view, choose the point, check that a press there lands, and try again when
|
|
10
|
+
* it does not. The host below sends each event through Playwright's own input
|
|
11
|
+
* methods, so the page sees the same trusted events as from any Playwright
|
|
12
|
+
* call, and the browser runs every channel raw.
|
|
13
|
+
*
|
|
14
|
+
* A raw() channel's parts are Playwright's: its moves are one event, its
|
|
15
|
+
* scroll into view is Playwright's. A part passed to myuri() is called with
|
|
16
|
+
* the page in place of the host. Inside it, Playwright calls are Playwright's
|
|
17
|
+
* own, so page.mouse.move in a move part moves the mouse once.
|
|
18
|
+
*
|
|
19
|
+
* What is wrapped, per page, and the channel that drives it:
|
|
20
|
+
*
|
|
21
|
+
* mouse Mouse.move / click / dblclick; Page/Frame/Locator click,
|
|
22
|
+
* dblclick, hover, check and uncheck, and the click that focuses
|
|
23
|
+
* a field before fill
|
|
24
|
+
* keyboard Keyboard.type / press; Page/Frame/Locator fill, type, press,
|
|
25
|
+
* and Locator.pressSequentially
|
|
26
|
+
* scroll Mouse.wheel; Locator.scrollIntoViewIfNeeded, and the scroll
|
|
27
|
+
* into view before a pointer action, fill, type or
|
|
28
|
+
* pressSequentially
|
|
29
|
+
*
|
|
30
|
+
* ElementHandle methods, tap, dragAndDrop and dragTo are Playwright's own. An
|
|
31
|
+
* ElementHandle cannot be measured and moved to as a Locator can, and a drag's
|
|
32
|
+
* moves happen inside Playwright's server.
|
|
33
|
+
*/
|
|
34
|
+
import { type HumanizeSetting } from "./humanize.js";
|
|
35
|
+
import type { OsName } from "./utils.js";
|
|
36
|
+
export declare const VIEWPORT = "() => [innerWidth, innerHeight]";
|
|
37
|
+
export declare const FRAME_ORIGIN = "e => { if (window === window.top) return null; const r = e.getBoundingClientRect(); return [r.x, r.y]; }";
|
|
38
|
+
/** The clock myuri's waits are on. */
|
|
39
|
+
export declare const clock: {
|
|
40
|
+
now: () => number;
|
|
41
|
+
sleep: (ms: number) => Promise<unknown>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Run myuri on every page of `target`, a Browser or BrowserContext, including
|
|
45
|
+
* pages and contexts opened later, as the `humanize` setting says. Other
|
|
46
|
+
* browsers in this process are untouched. `os` ("macos", "windows" or
|
|
47
|
+
* "linux") is the launch identity's, whose people myuri plans for.
|
|
48
|
+
* Camouwolf()/NewBrowser() call this themselves; for one from `connect()`,
|
|
49
|
+
* launch it without humanize.
|
|
50
|
+
*
|
|
51
|
+
* Every draw comes from one stream, of `humanize.seed` or a random seed.
|
|
52
|
+
*/
|
|
53
|
+
export declare function attach<T>(target: T, humanize: HumanizeSetting, os: OsName, iKnowWhatImDoing?: boolean): T;
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* myuri's smart actions on Playwright pages. The TypeScript twin of
|
|
3
|
+
* python/camoucore/src/camoucore/camouwolf/_humanize_playwright.py; both are held to the sequence
|
|
4
|
+
* in browser/tests/humanize/sequence.json.
|
|
5
|
+
*
|
|
6
|
+
* Each page of the browser (or persistent context) a humanize setting is
|
|
7
|
+
* attached to gets one myuri `Actions`. It owns the timing and motion of the
|
|
8
|
+
* page's input and the decisions around a click: scroll the element into
|
|
9
|
+
* view, choose the point, check that a press there lands, and try again when
|
|
10
|
+
* it does not. The host below sends each event through Playwright's own input
|
|
11
|
+
* methods, so the page sees the same trusted events as from any Playwright
|
|
12
|
+
* call, and the browser runs every channel raw.
|
|
13
|
+
*
|
|
14
|
+
* A raw() channel's parts are Playwright's: its moves are one event, its
|
|
15
|
+
* scroll into view is Playwright's. A part passed to myuri() is called with
|
|
16
|
+
* the page in place of the host. Inside it, Playwright calls are Playwright's
|
|
17
|
+
* own, so page.mouse.move in a move part moves the mouse once.
|
|
18
|
+
*
|
|
19
|
+
* What is wrapped, per page, and the channel that drives it:
|
|
20
|
+
*
|
|
21
|
+
* mouse Mouse.move / click / dblclick; Page/Frame/Locator click,
|
|
22
|
+
* dblclick, hover, check and uncheck, and the click that focuses
|
|
23
|
+
* a field before fill
|
|
24
|
+
* keyboard Keyboard.type / press; Page/Frame/Locator fill, type, press,
|
|
25
|
+
* and Locator.pressSequentially
|
|
26
|
+
* scroll Mouse.wheel; Locator.scrollIntoViewIfNeeded, and the scroll
|
|
27
|
+
* into view before a pointer action, fill, type or
|
|
28
|
+
* pressSequentially
|
|
29
|
+
*
|
|
30
|
+
* ElementHandle methods, tap, dragAndDrop and dragTo are Playwright's own. An
|
|
31
|
+
* ElementHandle cannot be measured and moved to as a Locator can, and a drag's
|
|
32
|
+
* moves happen inside Playwright's server.
|
|
33
|
+
*/
|
|
34
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
35
|
+
import { randomBytes } from "node:crypto";
|
|
36
|
+
import { Actions, HIT_TEST_JS, Missed, makeRng, } from "@jwriter20/myuri";
|
|
37
|
+
import { errors } from "playwright-core";
|
|
38
|
+
import { FILL_NEEDS_CLICK, pageFunction, patchFrameFill, } from "./driver_defaults.js";
|
|
39
|
+
import { CHANNELS, normalize, } from "./humanize.js";
|
|
40
|
+
import { LeakWarning, loadWarnings } from "./warnings.js";
|
|
41
|
+
const scope = new AsyncLocalStorage();
|
|
42
|
+
const within = (change, fn) => scope.run({ inPart: false, inPlaywright: false, ...scope.getStore(), ...change }, fn);
|
|
43
|
+
const SETUP = Symbol.for("camouwolf.humanize");
|
|
44
|
+
const ACTIONS = Symbol.for("camouwolf.humanize-actions");
|
|
45
|
+
const ROUTED_FRAMES = Symbol.for("camouwolf.humanize-routed");
|
|
46
|
+
const DISPATCH_ISOLATED = Symbol.for("camouwolf.humanize-dispatch");
|
|
47
|
+
// Byte-identical to the Python constants (tests/package-parity.test.ts).
|
|
48
|
+
export const VIEWPORT = "() => [innerWidth, innerHeight]";
|
|
49
|
+
// The element's client origin in its frame, or null in the top window, whose
|
|
50
|
+
// viewport is the page's.
|
|
51
|
+
export const FRAME_ORIGIN = "e => { if (window === window.top) return null; const r = e.getBoundingClientRect(); return [r.x, r.y]; }";
|
|
52
|
+
/** The clock myuri's waits are on. */
|
|
53
|
+
export const clock = {
|
|
54
|
+
now: () => performance.now(),
|
|
55
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
56
|
+
};
|
|
57
|
+
/** `fn` as Playwright's own: a call it makes on a wrapped method passes through. */
|
|
58
|
+
function direct(fn) {
|
|
59
|
+
return ((...args) => within({ inPlaywright: true }, () => fn(...args)));
|
|
60
|
+
}
|
|
61
|
+
/** myuri's host on one page: every event is a Playwright input call. */
|
|
62
|
+
function host(page) {
|
|
63
|
+
const { mouse, keyboard } = page;
|
|
64
|
+
const down = direct(mouse.down.bind(mouse));
|
|
65
|
+
const up = direct(mouse.up.bind(mouse));
|
|
66
|
+
const timeout = () => scope.getStore()?.timeout;
|
|
67
|
+
return {
|
|
68
|
+
move: direct(mouse.move.bind(mouse)),
|
|
69
|
+
click: async (button, clickCount, holdMs) => {
|
|
70
|
+
await down({ button, clickCount });
|
|
71
|
+
await clock.sleep(holdMs);
|
|
72
|
+
await up({ button, clickCount });
|
|
73
|
+
},
|
|
74
|
+
down: (button) => down({ button }),
|
|
75
|
+
up: (button) => up({ button }),
|
|
76
|
+
wheel: direct(mouse.wheel.bind(mouse)),
|
|
77
|
+
keyDown: direct(keyboard.down.bind(keyboard)),
|
|
78
|
+
keyUp: direct(keyboard.up.bind(keyboard)),
|
|
79
|
+
insertText: direct(keyboard.insertText.bind(keyboard)),
|
|
80
|
+
evaluate: (target, fn, arg) => target.evaluate(fn, arg, { timeout: timeout() }),
|
|
81
|
+
offset: async (target) => {
|
|
82
|
+
const origin = await target.evaluate(pageFunction(FRAME_ORIGIN), undefined, { timeout: timeout() });
|
|
83
|
+
if (origin === null)
|
|
84
|
+
return [0, 0];
|
|
85
|
+
const box = await target.boundingBox({ timeout: timeout() });
|
|
86
|
+
return box ? [box.x - origin[0], box.y - origin[1]] : null;
|
|
87
|
+
},
|
|
88
|
+
viewport: () => page.evaluate(pageFunction(VIEWPORT)),
|
|
89
|
+
now: () => clock.now(),
|
|
90
|
+
sleep: (ms) => clock.sleep(ms),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// ---- parts -----------------------------------------------------------------
|
|
94
|
+
const LOCATOR_ORIGINALS = new WeakMap();
|
|
95
|
+
function locatorOriginal(locator, name) {
|
|
96
|
+
return LOCATOR_ORIGINALS.get(locator.constructor)[name];
|
|
97
|
+
}
|
|
98
|
+
// What myuri calls for a raw() channel: the parts its other channels' flows use.
|
|
99
|
+
const RAW_PARTS = {
|
|
100
|
+
mouse: { move: (_host, x, y, { play }) => play([["move", x, y, 0]]) },
|
|
101
|
+
keyboard: {},
|
|
102
|
+
scroll: {
|
|
103
|
+
intoView: (_host, locator) => locatorOriginal(locator, "scrollIntoViewIfNeeded")(locator, {
|
|
104
|
+
timeout: scope.getStore()?.timeout,
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
class Setup {
|
|
109
|
+
engines;
|
|
110
|
+
os;
|
|
111
|
+
// One stream for every page, so two pages never replay the same draws.
|
|
112
|
+
rng;
|
|
113
|
+
constructor(engines, seed, os) {
|
|
114
|
+
this.engines = engines;
|
|
115
|
+
this.os = os;
|
|
116
|
+
this.rng = makeRng(seed);
|
|
117
|
+
}
|
|
118
|
+
/** Whether myuri drives the channel for the call being made. */
|
|
119
|
+
drives(channel) {
|
|
120
|
+
const current = scope.getStore();
|
|
121
|
+
return (this.engines[channel].engine === "myuri" &&
|
|
122
|
+
!current?.inPart &&
|
|
123
|
+
!current?.inPlaywright);
|
|
124
|
+
}
|
|
125
|
+
actions(page) {
|
|
126
|
+
const parts = {};
|
|
127
|
+
for (const channel of CHANNELS) {
|
|
128
|
+
const { engine, options } = this.engines[channel];
|
|
129
|
+
if (engine === "raw")
|
|
130
|
+
Object.assign(parts, RAW_PARTS[channel]);
|
|
131
|
+
else
|
|
132
|
+
for (const [name, fn] of Object.entries(options))
|
|
133
|
+
if (name !== "wpm")
|
|
134
|
+
// A part of the caller's, called with the page in place of the host;
|
|
135
|
+
// one that throws rejects, as Playwright's methods do.
|
|
136
|
+
parts[name] = async (_host, ...args) => within({ inPart: true }, () => fn(page, ...args));
|
|
137
|
+
}
|
|
138
|
+
const wpm = this.engines.keyboard.options.wpm;
|
|
139
|
+
return new Actions(host(page), this.rng, {
|
|
140
|
+
os: this.os,
|
|
141
|
+
// Camouwolf identities point with a mouse, whose wheel turns in notches.
|
|
142
|
+
device: "mouse",
|
|
143
|
+
settings: wpm === undefined ? undefined : { typing: { wpm } },
|
|
144
|
+
parts,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// ---- flows -----------------------------------------------------------------
|
|
149
|
+
const timed = (timeout, fn) => within({ timeout }, fn);
|
|
150
|
+
function timeoutOf(locator, options) {
|
|
151
|
+
return options.timeout ?? locator.page()._timeoutSettings.timeout({}).timeout;
|
|
152
|
+
}
|
|
153
|
+
/** myuri's click (or, for hover, its move) onto the locator, failing as
|
|
154
|
+
* Playwright's action does: a timeout naming why the point was never reached. */
|
|
155
|
+
async function reach(actions, locator, name, options, timeout) {
|
|
156
|
+
try {
|
|
157
|
+
await actions.click(locator, {
|
|
158
|
+
button: options.button ?? "left",
|
|
159
|
+
clickCount: options.clickCount ?? (name === "dblclick" ? 2 : 1),
|
|
160
|
+
modifiers: options.modifiers ?? [],
|
|
161
|
+
position: options.position,
|
|
162
|
+
force: Boolean(options.force),
|
|
163
|
+
press: name !== "hover",
|
|
164
|
+
// 0 is no timeout, as in Playwright.
|
|
165
|
+
timeout,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (!(error instanceof Missed))
|
|
170
|
+
throw error;
|
|
171
|
+
throw new errors.TimeoutError(`Timeout ${timeout}ms exceeded: ${name} ${error.message}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** click / dblclick / hover / check / uncheck. */
|
|
175
|
+
function pointer(name) {
|
|
176
|
+
return (setup, actions, locator, original, [options = {}]) => {
|
|
177
|
+
if (options.trial || !(setup.drives("mouse") || setup.drives("scroll")))
|
|
178
|
+
return null;
|
|
179
|
+
const timeout = timeoutOf(locator, options);
|
|
180
|
+
const mouse = setup.drives("mouse");
|
|
181
|
+
return timed(timeout, async () => {
|
|
182
|
+
if (!mouse) {
|
|
183
|
+
await actions.intoView(locator);
|
|
184
|
+
return original(locator, options);
|
|
185
|
+
}
|
|
186
|
+
const checkbox = name === "check" || name === "uncheck";
|
|
187
|
+
if (checkbox &&
|
|
188
|
+
(await locator.isChecked({ timeout })) === (name === "check"))
|
|
189
|
+
return;
|
|
190
|
+
await reach(actions, locator, name, options, timeout);
|
|
191
|
+
if (checkbox &&
|
|
192
|
+
(await locator.isChecked({ timeout })) !== (name === "check"))
|
|
193
|
+
throw new Error(`Clicking the checkbox did not change its state (${name})`);
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** The click before a fill (driver_defaults), with myuri's move when it drives
|
|
198
|
+
* the mouse. The fill then finds the field focused. */
|
|
199
|
+
async function clickToFocus(setup, actions, locator, options) {
|
|
200
|
+
const timeout = timeoutOf(locator, options);
|
|
201
|
+
if (!(await locator.evaluate(pageFunction(FILL_NEEDS_CLICK), undefined, {
|
|
202
|
+
timeout,
|
|
203
|
+
})))
|
|
204
|
+
return;
|
|
205
|
+
await actions.intoView(locator);
|
|
206
|
+
if ((await locator.evaluate(HIT_TEST_JS, null, { timeout })) !== null)
|
|
207
|
+
return;
|
|
208
|
+
if (setup.drives("mouse"))
|
|
209
|
+
await reach(actions, locator, "click", { force: options.force }, timeout);
|
|
210
|
+
else
|
|
211
|
+
await locatorOriginal(locator, "click")(locator, {
|
|
212
|
+
timeout,
|
|
213
|
+
force: options.force,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/** fill / type / pressSequentially / press on a locator. */
|
|
217
|
+
function keys(kind) {
|
|
218
|
+
return (setup, actions, locator, original, [text, options = {}]) => {
|
|
219
|
+
const keyboard = setup.drives("keyboard");
|
|
220
|
+
const scroll = kind !== "press" && setup.drives("scroll");
|
|
221
|
+
const mouse = kind === "fill" && setup.drives("mouse");
|
|
222
|
+
if (!(keyboard || mouse || scroll))
|
|
223
|
+
return null;
|
|
224
|
+
return timed(options.timeout, async () => {
|
|
225
|
+
if (scroll)
|
|
226
|
+
await actions.intoView(locator);
|
|
227
|
+
if (kind === "fill")
|
|
228
|
+
await clickToFocus(setup, actions, locator, options);
|
|
229
|
+
if (!keyboard || text === "")
|
|
230
|
+
return original(locator, text, options);
|
|
231
|
+
const { timeout, force } = options;
|
|
232
|
+
// Typing then replaces what the field held, as fill() does.
|
|
233
|
+
if (kind === "fill")
|
|
234
|
+
await locator.selectText({ force, timeout });
|
|
235
|
+
else
|
|
236
|
+
await locator.focus({ timeout });
|
|
237
|
+
return kind === "press" ? actions.key(text) : actions.type(text);
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const scrollLocator = (setup, actions, locator, _original, [options = {}]) => setup.drives("scroll")
|
|
242
|
+
? timed(options.timeout, () => actions.intoView(locator))
|
|
243
|
+
: null;
|
|
244
|
+
const LOCATOR_FLOWS = {
|
|
245
|
+
click: pointer("click"),
|
|
246
|
+
dblclick: pointer("dblclick"),
|
|
247
|
+
hover: pointer("hover"),
|
|
248
|
+
check: pointer("check"),
|
|
249
|
+
uncheck: pointer("uncheck"),
|
|
250
|
+
fill: keys("fill"),
|
|
251
|
+
type: keys("type"),
|
|
252
|
+
pressSequentially: keys("type"),
|
|
253
|
+
press: keys("press"),
|
|
254
|
+
scrollIntoViewIfNeeded: scrollLocator,
|
|
255
|
+
};
|
|
256
|
+
/** Route a Locator class's input methods through myuri on the locator's page.
|
|
257
|
+
* A page with no humanize setting (any other browser) gets the original. */
|
|
258
|
+
function patchLocatorClass(cls) {
|
|
259
|
+
if (LOCATOR_ORIGINALS.has(cls))
|
|
260
|
+
return;
|
|
261
|
+
const originals = {};
|
|
262
|
+
LOCATOR_ORIGINALS.set(cls, originals);
|
|
263
|
+
for (const [name, flow] of Object.entries(LOCATOR_FLOWS)) {
|
|
264
|
+
const original = cls.prototype[name];
|
|
265
|
+
originals[name] = direct((locator, ...args) => original.apply(locator, args));
|
|
266
|
+
cls.prototype[name] = function (...args) {
|
|
267
|
+
const page = this.page();
|
|
268
|
+
const setup = page?.[SETUP];
|
|
269
|
+
if (!setup)
|
|
270
|
+
return original.apply(this, args);
|
|
271
|
+
return (flow(setup, page[ACTIONS], this, originals[name], args) ??
|
|
272
|
+
originals[name](this, ...args));
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// Page and Frame methods that take a selector, routed to the Locator method of
|
|
277
|
+
// the same name when myuri drives one of these channels.
|
|
278
|
+
const PAGE_ROUTES = {
|
|
279
|
+
click: ["mouse", "scroll"],
|
|
280
|
+
dblclick: ["mouse", "scroll"],
|
|
281
|
+
hover: ["mouse", "scroll"],
|
|
282
|
+
check: ["mouse", "scroll"],
|
|
283
|
+
uncheck: ["mouse", "scroll"],
|
|
284
|
+
fill: ["mouse", "keyboard", "scroll"],
|
|
285
|
+
type: ["keyboard", "scroll"],
|
|
286
|
+
press: ["keyboard"],
|
|
287
|
+
};
|
|
288
|
+
const ROUTES_WITH_TEXT = ["fill", "type", "press"];
|
|
289
|
+
const myuriOn = (setup, channels) => channels.some((channel) => setup?.engines[channel].engine === "myuri");
|
|
290
|
+
function routed(owner, name) {
|
|
291
|
+
const texts = ROUTES_WITH_TEXT.includes(name) ? 1 : 0;
|
|
292
|
+
return (selector, ...rest) => {
|
|
293
|
+
const { strict, ...options } = rest[texts] ?? {};
|
|
294
|
+
const locator = owner.locator(selector);
|
|
295
|
+
// Without strict, Page and Frame methods act on the first match.
|
|
296
|
+
return (strict ? locator : locator.first())[name](...rest.slice(0, texts), options);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function attachPage(page, setup) {
|
|
300
|
+
if (page[SETUP])
|
|
301
|
+
return;
|
|
302
|
+
const actions = setup.actions(page);
|
|
303
|
+
page[ACTIONS] = actions;
|
|
304
|
+
page[SETUP] = setup;
|
|
305
|
+
patchLocatorClass(page.locator("html").constructor);
|
|
306
|
+
const { mouse, keyboard } = page;
|
|
307
|
+
const o = {
|
|
308
|
+
move: direct(mouse.move.bind(mouse)),
|
|
309
|
+
click: direct(mouse.click.bind(mouse)),
|
|
310
|
+
dblclick: direct(mouse.dblclick.bind(mouse)),
|
|
311
|
+
wheel: direct(mouse.wheel.bind(mouse)),
|
|
312
|
+
type: direct(keyboard.type.bind(keyboard)),
|
|
313
|
+
press: direct(keyboard.press.bind(keyboard)),
|
|
314
|
+
};
|
|
315
|
+
mouse.move = (x, y, options) => {
|
|
316
|
+
if (setup.drives("mouse"))
|
|
317
|
+
return actions.move(x, y);
|
|
318
|
+
actions.moved(x, y);
|
|
319
|
+
return o.move(x, y, options);
|
|
320
|
+
};
|
|
321
|
+
const clicking = (original, double) => (x, y, options = {}) => {
|
|
322
|
+
if (!setup.drives("mouse")) {
|
|
323
|
+
actions.moved(x, y);
|
|
324
|
+
return original(x, y, options);
|
|
325
|
+
}
|
|
326
|
+
const count = double ? 2 : (options.clickCount ?? 1);
|
|
327
|
+
return actions.clickAt(x, y, options.button ?? "left", count);
|
|
328
|
+
};
|
|
329
|
+
mouse.click = clicking(o.click, false);
|
|
330
|
+
mouse.dblclick = clicking(o.dblclick, true);
|
|
331
|
+
// A delay is myuri's to plan.
|
|
332
|
+
mouse.wheel = (dx, dy) => setup.drives("scroll") ? actions.wheel(dx, dy) : o.wheel(dx, dy);
|
|
333
|
+
keyboard.type = (text, options) => setup.drives("keyboard") ? actions.type(text) : o.type(text, options);
|
|
334
|
+
keyboard.press = (key, options) => setup.drives("keyboard") ? actions.key(key) : o.press(key, options);
|
|
335
|
+
// page.click(selector) and friends: the same flow as the locator's.
|
|
336
|
+
for (const [name, channels] of Object.entries(PAGE_ROUTES))
|
|
337
|
+
if (myuriOn(setup, channels))
|
|
338
|
+
page[name] = routed(page, name);
|
|
339
|
+
patchFrameClass(Object.getPrototypeOf(page.mainFrame()));
|
|
340
|
+
}
|
|
341
|
+
/** Route a Frame class's input methods as a page's are, for frames of a page
|
|
342
|
+
* where myuri drives one of the channels. */
|
|
343
|
+
function patchFrameClass(prototype) {
|
|
344
|
+
if (Object.hasOwn(prototype, ROUTED_FRAMES))
|
|
345
|
+
return;
|
|
346
|
+
prototype[ROUTED_FRAMES] = true;
|
|
347
|
+
// Fill's click-first hook stays inside this routing, whichever came first,
|
|
348
|
+
// so myuri plans a fill's click once.
|
|
349
|
+
patchFrameFill(prototype);
|
|
350
|
+
for (const [name, channels] of Object.entries(PAGE_ROUTES)) {
|
|
351
|
+
const original = prototype[name];
|
|
352
|
+
prototype[name] = function (...args) {
|
|
353
|
+
if (scope.getStore()?.inPlaywright ||
|
|
354
|
+
!myuriOn(this.page()?.[SETUP], channels))
|
|
355
|
+
return original.apply(this, args);
|
|
356
|
+
return routed(this, name)(...args);
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function attachContext(context, setup) {
|
|
361
|
+
if (context[SETUP])
|
|
362
|
+
return;
|
|
363
|
+
context[SETUP] = setup;
|
|
364
|
+
context.on("page", (page) => attachPage(page, setup));
|
|
365
|
+
for (const page of context.pages())
|
|
366
|
+
attachPage(page, setup);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* In process, Playwright's server answers inside the caller's async context, so
|
|
370
|
+
* an event handler (a popup's, say) would inherit the scope of whichever wrapped
|
|
371
|
+
* call was in flight.
|
|
372
|
+
*/
|
|
373
|
+
function isolateDispatch(connection) {
|
|
374
|
+
if (!connection || connection[DISPATCH_ISOLATED])
|
|
375
|
+
return;
|
|
376
|
+
connection[DISPATCH_ISOLATED] = true;
|
|
377
|
+
const { dispatch } = connection;
|
|
378
|
+
connection.dispatch = function (...args) {
|
|
379
|
+
return scope.exit(() => dispatch.apply(this, args));
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Run myuri on every page of `target`, a Browser or BrowserContext, including
|
|
384
|
+
* pages and contexts opened later, as the `humanize` setting says. Other
|
|
385
|
+
* browsers in this process are untouched. `os` ("macos", "windows" or
|
|
386
|
+
* "linux") is the launch identity's, whose people myuri plans for.
|
|
387
|
+
* Camouwolf()/NewBrowser() call this themselves; for one from `connect()`,
|
|
388
|
+
* launch it without humanize.
|
|
389
|
+
*
|
|
390
|
+
* Every draw comes from one stream, of `humanize.seed` or a random seed.
|
|
391
|
+
*/
|
|
392
|
+
export function attach(target, humanize, os, iKnowWhatImDoing) {
|
|
393
|
+
const { engines, seed } = normalize(humanize);
|
|
394
|
+
if (CHANNELS.every((channel) => engines[channel].engine === "raw"))
|
|
395
|
+
return target;
|
|
396
|
+
const owner = target;
|
|
397
|
+
if (owner[SETUP])
|
|
398
|
+
throw new Error("humanize is already attached to this browser");
|
|
399
|
+
if (owner._connection?.isRemote())
|
|
400
|
+
LeakWarning.warn(loadWarnings().humanize_remote, iKnowWhatImDoing);
|
|
401
|
+
isolateDispatch(owner._connection);
|
|
402
|
+
const setup = new Setup(engines, seed ?? randomBytes(4).readUInt32BE(), os);
|
|
403
|
+
if (typeof owner.newContext !== "function") {
|
|
404
|
+
// A BrowserContext (a persistent context).
|
|
405
|
+
attachContext(owner, setup);
|
|
406
|
+
return target;
|
|
407
|
+
}
|
|
408
|
+
owner[SETUP] = setup;
|
|
409
|
+
for (const context of owner.contexts())
|
|
410
|
+
attachContext(context, setup);
|
|
411
|
+
const then = {
|
|
412
|
+
newContext: (context) => {
|
|
413
|
+
attachContext(context, setup);
|
|
414
|
+
return context;
|
|
415
|
+
},
|
|
416
|
+
newPage: (page) => {
|
|
417
|
+
attachContext(page.context(), setup);
|
|
418
|
+
attachPage(page, setup);
|
|
419
|
+
return page;
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
for (const [name, attach] of Object.entries(then)) {
|
|
423
|
+
const original = owner[name];
|
|
424
|
+
owner[name] = async (...args) => attach(await original.apply(owner, args));
|
|
425
|
+
}
|
|
426
|
+
return target;
|
|
427
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Injection points (tests point the addon directory at a fixture). */
|
|
2
|
+
export declare const addonsDeps: {
|
|
3
|
+
addonsDir: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Default addons. `camouwolf fetch` installs them, unpacked, under
|
|
7
|
+
* <cache>/addons/<name>/.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DefaultAddons: {
|
|
10
|
+
readonly UBO: "UBO";
|
|
11
|
+
};
|
|
12
|
+
export type DefaultAddon = keyof typeof DefaultAddons;
|
|
13
|
+
/** name -> the pin file under data/ that says what to download. */
|
|
14
|
+
export declare const ADDON_PINS: Readonly<Record<DefaultAddon, string>>;
|
|
15
|
+
export interface AddonPin {
|
|
16
|
+
name: string;
|
|
17
|
+
version: string;
|
|
18
|
+
url: string;
|
|
19
|
+
sha256: string;
|
|
20
|
+
}
|
|
21
|
+
/** The pinned release of a default addon: name, version, url, sha256. */
|
|
22
|
+
export declare function addonPin(addon: DefaultAddon): AddonPin;
|
|
23
|
+
/**
|
|
24
|
+
* Confirms that the addon paths are valid.
|
|
25
|
+
*
|
|
26
|
+
* Chromium treats an extension it cannot load as a warning on stderr and
|
|
27
|
+
* starts without it, so a mistyped path would otherwise launch a browser that
|
|
28
|
+
* just lacks the extension. --load-extension takes an unpacked directory; a
|
|
29
|
+
* .crx is ignored.
|
|
30
|
+
*/
|
|
31
|
+
export declare function confirmPaths(paths: string[]): void;
|
|
32
|
+
/** Returns the path a default addon is installed at. */
|
|
33
|
+
export declare function getAddonPath(addonName: string): string;
|
|
34
|
+
/** Whether the pinned version of a default addon is installed. */
|
|
35
|
+
export declare function isInstalled(addon: DefaultAddon): boolean;
|
|
36
|
+
/** Download, verify and unpack every default addon. Returns their paths. */
|
|
37
|
+
export declare function fetchDefaultAddons(replace?: boolean): Promise<string[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Adds the installed default addons, minus any specified in excludeList, to
|
|
40
|
+
* addonsList.
|
|
41
|
+
*/
|
|
42
|
+
export declare function addDefaultAddons(addonsList: string[], excludeList?: readonly DefaultAddon[] | null): void;
|