@namzu/browser 0.1.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE.md +110 -0
  3. package/README.md +149 -0
  4. package/dist/classifier.d.ts +70 -0
  5. package/dist/classifier.d.ts.map +1 -0
  6. package/dist/classifier.js +147 -0
  7. package/dist/classifier.js.map +1 -0
  8. package/dist/detect.d.ts +126 -0
  9. package/dist/detect.d.ts.map +1 -0
  10. package/dist/detect.js +282 -0
  11. package/dist/detect.js.map +1 -0
  12. package/dist/errors.d.ts +64 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +99 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/host.d.ts +167 -0
  17. package/dist/host.d.ts.map +1 -0
  18. package/dist/host.js +1024 -0
  19. package/dist/host.js.map +1 -0
  20. package/dist/index.d.ts +17 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +10 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/page-scripts.d.ts +51 -0
  25. package/dist/page-scripts.d.ts.map +1 -0
  26. package/dist/page-scripts.js +123 -0
  27. package/dist/page-scripts.js.map +1 -0
  28. package/dist/policy.d.ts +61 -0
  29. package/dist/policy.d.ts.map +1 -0
  30. package/dist/policy.js +150 -0
  31. package/dist/policy.js.map +1 -0
  32. package/dist/profiles.d.ts +107 -0
  33. package/dist/profiles.d.ts.map +1 -0
  34. package/dist/profiles.js +312 -0
  35. package/dist/profiles.js.map +1 -0
  36. package/dist/relay.d.ts +27 -0
  37. package/dist/relay.d.ts.map +1 -0
  38. package/dist/relay.js +69 -0
  39. package/dist/relay.js.map +1 -0
  40. package/dist/snapshot.d.ts +101 -0
  41. package/dist/snapshot.d.ts.map +1 -0
  42. package/dist/snapshot.js +265 -0
  43. package/dist/snapshot.js.map +1 -0
  44. package/dist/windows-bridge-script.d.ts +29 -0
  45. package/dist/windows-bridge-script.d.ts.map +1 -0
  46. package/dist/windows-bridge-script.js +161 -0
  47. package/dist/windows-bridge-script.js.map +1 -0
  48. package/dist/windows-bridge.d.ts +120 -0
  49. package/dist/windows-bridge.d.ts.map +1 -0
  50. package/dist/windows-bridge.js +267 -0
  51. package/dist/windows-bridge.js.map +1 -0
  52. package/dist/windows-engine.d.ts +55 -0
  53. package/dist/windows-engine.d.ts.map +1 -0
  54. package/dist/windows-engine.js +154 -0
  55. package/dist/windows-engine.js.map +1 -0
  56. package/dist/wsl.d.ts +52 -0
  57. package/dist/wsl.d.ts.map +1 -0
  58. package/dist/wsl.js +134 -0
  59. package/dist/wsl.js.map +1 -0
  60. package/package.json +74 -0
  61. package/src/classifier.ts +191 -0
  62. package/src/detect.ts +432 -0
  63. package/src/errors.ts +121 -0
  64. package/src/host.ts +1217 -0
  65. package/src/index.ts +79 -0
  66. package/src/page-scripts.ts +154 -0
  67. package/src/policy.ts +190 -0
  68. package/src/profiles.ts +373 -0
  69. package/src/relay.ts +101 -0
  70. package/src/snapshot.ts +317 -0
  71. package/src/windows-bridge-script.ts +160 -0
  72. package/src/windows-bridge.ts +358 -0
  73. package/src/windows-engine.ts +208 -0
  74. package/src/wsl.ts +155 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # @namzu/browser
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2b96136: First release of `@namzu/browser`: a browser engine for the SDK's `browser` and `browser_act` tools.
8
+
9
+ `PlaywrightBrowserHost` implements `BrowserHost`. Pass it to `createBrowserTools(host)`. It runs an installed Google Chrome, or Playwright's Chromium if Chrome is missing. The browser uses a persistent profile under `NAMZU_HOME/browser/profiles/<name>`, so a site you signed in to once stays signed in. Nothing launches until the first call.
10
+
11
+ Whatever the permission gate allowed, the host also enforces the following:
12
+
13
+ - A `browser_act` call's `origin` must equal the live page's origin.
14
+ - A navigation, redirect or popup may only land on a site the `sites` rules allow at `read` or `act`, or on one the caller asked to open. A top-level request anywhere else is stopped before it is sent. A redirect is caught when it lands and cleared to `about:blank`.
15
+ - A sign-in, a second factor, a CAPTCHA, a bot check or an HTTP 401/407 response stops the call with `browser_human_required`. The error carries the profile and a `namzu browser login <profile> <url>` command.
16
+ - Nothing is typed into a password or one-time-code field, and snapshots never show their values.
17
+ - Invisible text is left out of snapshots.
18
+ - Downloads are cancelled and reported.
19
+
20
+ `detectBrowserEnvironment(env, platform, probes, options)` works out where the browser runs and whether its window shows, without launching anything.
21
+
22
+ Inside WSL, with interop on and Chrome or Edge installed on Windows, the host drives the Windows browser (`windows-cdp`) and needs nothing installed on Windows. It starts `powershell.exe` through interop with a bridge script that starts the browser on a dedicated profile under `%LOCALAPPDATA%\namzu\browser\profiles\<name>` (or attaches to it when it is already running) and relays CDP over its standard streams, because WSL's NAT networking cannot reach Windows' `127.0.0.1`. Playwright connects to a relay on WSL's `127.0.0.1` at a random 64-hex-digit path. Under mirrored networking the host tries the browser's port directly first. Every namzu process on a profile shares one browser, and the last one to finish closes it. If namzu dies, the bridge closes the browser it started, and never one it did not. A systemd service without `WSL_INTEROP` gets a socket from `/run/WSL`. Pass `windowsBrowser: 'msedge'` to detection for Edge. Host option `windowsLaunchTimeoutMs` bounds starting the Windows browser. WSL helpers exported: `windowsPathToWsl`, `wslPathToWindows`, `wslNetworkingMode`, `wslInteropSocket`, `findWslInteropSocket`, `parseDevToolsActivePort`, `bridgeArguments`, `encodePowerShellCommand`, `WindowsBridgeError` and their neighbours. Adds a dependency on `ws`.
23
+
24
+ Also exported: `BrowserProfileStore`, `BrowserLeaseStore`, `BrowserSitePolicy`, `classifyHumanRequired`, `BrowserUnavailableError`, `ProfileBusyError`, and the SDK's refusal shapes as classes.
25
+
26
+ `playwright-core` is pinned exactly at 1.63.0, whose Chromium is build 1243. Install that browser with `npx playwright-core@1.63.0 install chromium`, unless Google Chrome is installed. Requires `@namzu/sdk` 44.4.0 or later, the first version with the browser tool contract.
27
+
28
+ See `docs/sdk/browser-host.md`.
29
+
30
+ ### Patch Changes
31
+
32
+ - 2b96136: `back`, `forward` and `reload` return once the page is back. They waited for `domcontentloaded`, which a page restored from the back-forward cache never fires, so going back in the Windows browser from WSL took 30 seconds and then failed although the page had already returned. They now wait for the navigation to commit, then up to 5 seconds for the document. A move the back-forward cache answered no longer says there is no page to go back to.
package/LICENSE.md ADDED
@@ -0,0 +1,110 @@
1
+ # Functional Source License, Version 1.1, MIT Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-MIT
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Cogitave
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the MIT license that is effective on the second anniversary of the date we make
91
+ the Software available. On or after that date, you may use the Software under
92
+ the MIT license, in which case the following will apply:
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98
+ of the Software, and to permit persons to whom the Software is furnished to do
99
+ so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ <!-- okf
2
+ type: Reference
3
+ title: "@namzu/browser"
4
+ description: >-
5
+ A browser host for the SDK's browser tools: Chromium driven by Playwright on
6
+ a persistent profile (the Windows browser when running in WSL),
7
+ accessibility snapshots with element refs, a site policy checked after
8
+ every navigation, and a stop for anything only a person should do.
9
+ tags: [readme, package, browser]
10
+ status: draft
11
+ generated: { by: human:bahadirarda, at: 2026-09-23T00:00:00Z }
12
+ -->
13
+
14
+ <div align="center">
15
+
16
+ <h1>@namzu/browser</h1>
17
+
18
+ **A web browser for Namzu agents.**
19
+
20
+ [![npm](https://img.shields.io/npm/v/@namzu/browser.svg)](https://www.npmjs.com/package/@namzu/browser)
21
+ [![build](https://github.com/cogitave/namzu/actions/workflows/ci.yml/badge.svg)](https://github.com/cogitave/namzu/actions/workflows/ci.yml)
22
+ [![license](https://img.shields.io/badge/license-FSL--1.1--MIT-blue.svg)](https://github.com/cogitave/namzu/blob/main/LICENSE.md)
23
+
24
+ [Install](#install) · [Usage](#usage) · [WSL](#wsl) · [What it enforces](#what-it-enforces) · [Documentation](#documentation)
25
+
26
+ </div>
27
+
28
+ ---
29
+
30
+ `PlaywrightBrowserHost` implements the SDK's `BrowserHost`, so
31
+ `createBrowserTools(host)` gives a model the `browser` and `browser_act` tools
32
+ over a real browser. It runs Google Chrome when one is installed and
33
+ Playwright's Chromium otherwise, on a persistent profile under
34
+ `NAMZU_HOME/browser/profiles/<name>`, so a site you signed in to once stays
35
+ signed in.
36
+
37
+ Nothing starts when the host is constructed. The browser is launched by the
38
+ first call that needs it.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pnpm add @namzu/sdk @namzu/browser
44
+ npx playwright-core@1.63.0 install chromium # unless Google Chrome is installed
45
+ ```
46
+
47
+ `@namzu/sdk` is a peer dependency. `playwright-core` is pinned exactly: the
48
+ element refs rest on a Playwright selector that is not documented, and the
49
+ pin is what keeps them working.
50
+
51
+ ## Usage
52
+
53
+ ```ts
54
+ import { PlaywrightBrowserHost } from '@namzu/browser'
55
+ import { ToolRegistry, createBrowserTools } from '@namzu/sdk'
56
+
57
+ const host = new PlaywrightBrowserHost({
58
+ profile: 'work',
59
+ sites: {
60
+ 'https://github.com': 'act',
61
+ 'https://*.github.com': 'read',
62
+ '*': 'ask',
63
+ },
64
+ })
65
+ for (const warning of host.warnings) console.warn(warning)
66
+
67
+ const registry = new ToolRegistry()
68
+ for (const tool of createBrowserTools(host)) registry.register(tool)
69
+
70
+ async function shutdown(): Promise<void> {
71
+ await host.dispose()
72
+ }
73
+ ```
74
+
75
+ Where the browser runs, and whether its window is shown, is decided from the
76
+ environment. Call `detectBrowserEnvironment` to see the decision without
77
+ launching anything:
78
+
79
+ ```ts
80
+ import { detectBrowserEnvironment, nodeBrowserProbes, runnableBrowserPlan } from '@namzu/browser'
81
+
82
+ const plan = runnableBrowserPlan(
83
+ detectBrowserEnvironment(process.env, process.platform, nodeBrowserProbes, {
84
+ mode: 'unattended',
85
+ }),
86
+ )
87
+ console.log(plan.engine, plan.headless, plan.unavailableReason ?? 'ready', plan.warnings)
88
+ ```
89
+
90
+ ## WSL
91
+
92
+ Inside WSL, with interop on and Chrome or Edge installed on Windows, the
93
+ host drives the Windows browser (`windows-cdp`): the window appears on the
94
+ Windows desktop, and sites see a Windows browser. Nothing is installed on
95
+ Windows. The host starts `powershell.exe` through interop with a script that
96
+ starts the browser on a dedicated profile under
97
+ `%LOCALAPPDATA%\namzu\browser\profiles\<name>` with remote debugging on a
98
+ port the browser picks, and relays CDP over the script's standard streams,
99
+ because WSL's default NAT networking cannot reach Windows' `127.0.0.1`.
100
+ Playwright connects to a relay on WSL's `127.0.0.1` at an unguessable path.
101
+ Under mirrored networking the host connects to the browser's port directly
102
+ and uses the relay only if that fails.
103
+
104
+ ```ts
105
+ import { PlaywrightBrowserHost, detectBrowserEnvironment, nodeBrowserProbes } from '@namzu/browser'
106
+
107
+ // Edge instead of Chrome, headless, for a run nobody watches.
108
+ const plan = detectBrowserEnvironment(process.env, process.platform, nodeBrowserProbes, {
109
+ mode: 'unattended',
110
+ windowsBrowser: 'msedge',
111
+ })
112
+ const host = new PlaywrightBrowserHost({ profile: 'reports', plan, windowsLaunchTimeoutMs: 90_000 })
113
+ ```
114
+
115
+ - The operator's own Chrome profile is never used or touched: Chrome 136
116
+ and later refuse remote debugging on it anyway.
117
+ - Every namzu process on a profile shares one browser. The last one to
118
+ finish closes it; `keepOpen` leaves it running. If namzu dies, the bridge
119
+ closes the browser it started, and only that one.
120
+ - A systemd service has no `WSL_INTEROP`; the host hands `powershell.exe` a
121
+ socket from `/run/WSL`.
122
+ - Adds about 2 ms to a snapshot and 35 ms to a screenshot; a 3.5 MB
123
+ full-page screenshot takes about a second.
124
+
125
+ ## What it enforces
126
+
127
+ Whatever the permission gate allowed:
128
+
129
+ - A `browser_act` call runs only if its `origin` is the live page's origin.
130
+ - A page may stay loaded only if its origin is at `read` or `act` in the site
131
+ rules, or the caller asked to open it this session. A link, script or
132
+ popup heading anywhere else is stopped before the request is sent. A
133
+ redirect is caught when it lands and the tab is cleared to `about:blank`.
134
+ - A sign-in page, a second factor, a CAPTCHA, a bot check or an HTTP
135
+ credential prompt stops the call with `browser_human_required` and the
136
+ command that opens a visible window for a person.
137
+ - Nothing is typed into a password or one-time-code field, and their values
138
+ never appear in a snapshot.
139
+ - Downloads are cancelled and reported. Text nobody can see (`aria-hidden`,
140
+ off-page, transparent, 1-pixel) is left out of snapshots.
141
+
142
+ ## Documentation
143
+
144
+ - [The browser host](https://github.com/cogitave/namzu/blob/main/docs/sdk/browser-host.md)
145
+ - [The browser tools](https://github.com/cogitave/namzu/blob/main/docs/sdk/browser-tools.md)
146
+
147
+ ## License
148
+
149
+ FSL-1.1-MIT, converting to MIT two years after each release.
@@ -0,0 +1,70 @@
1
+ import type { BrowserHumanRequiredReason } from '@namzu/sdk';
2
+ /**
3
+ * What the host read off a page to decide whether it needs a person. Every
4
+ * field is gathered by the host from the browser, never from the model.
5
+ */
6
+ export interface BrowserPageSignals {
7
+ /** The main frame's address. */
8
+ readonly url: string;
9
+ /** The document title. */
10
+ readonly title: string;
11
+ /** HTTP status of the main document's last response, when known. */
12
+ readonly status?: number;
13
+ /** Visible password fields (`type=password`, `autocomplete=current-password`). */
14
+ readonly passwordFields: number;
15
+ /** Visible one-time-code fields (`autocomplete=one-time-code`, or named like one). */
16
+ readonly oneTimeCodeFields: number;
17
+ /** Addresses of visible child frames, the only place a CAPTCHA widget is drawn. */
18
+ readonly frameUrls: readonly string[];
19
+ }
20
+ export interface BrowserHumanClassifierOptions {
21
+ /**
22
+ * More sign-in addresses, as `host` (`sso.example.com`) or `host/path`
23
+ * prefix (`example.com/account/login`). Added to {@link SIGN_IN_ADDRESSES}.
24
+ */
25
+ readonly signInAddresses?: readonly string[];
26
+ }
27
+ /**
28
+ * Hosts and host/path prefixes that are a sign-in wherever they appear. The
29
+ * path forms below catch the rest (`/login`, `/signin`, `/sso`, …).
30
+ */
31
+ export declare const SIGN_IN_ADDRESSES: readonly string[];
32
+ /**
33
+ * Hosts that draw CAPTCHA and bot-check widgets in a frame. A frame served
34
+ * from one of these (or a subdomain) is a challenge.
35
+ */
36
+ export declare const CAPTCHA_FRAME_HOSTS: readonly string[];
37
+ /** Is `frameUrl` a CAPTCHA or bot-check widget? Invisible-badge frames are not. */
38
+ export declare function isCaptchaFrame(frameUrl: string): boolean;
39
+ /** Is `title` the title of a bot check or block page? */
40
+ export declare function isBotBlockTitle(title: string): boolean;
41
+ /** Is `rawUrl` a sign-in address, by host list or by path? */
42
+ export declare function isSignInAddress(rawUrl: string, options?: BrowserHumanClassifierOptions): boolean;
43
+ /**
44
+ * Does the page need a person, and why? `undefined` when it does not.
45
+ *
46
+ * Order matters only for the reason reported: an HTTP credential prompt,
47
+ * then a CAPTCHA, a bot wall, a second factor, and last a sign-in. All of it
48
+ * is read by the host; nothing the model says reaches this function.
49
+ *
50
+ * It errs toward stopping. A page with a visible password box is treated as
51
+ * a sign-in even when it is a settings page, because the cost of a false stop
52
+ * is a question to the operator and the cost of a false pass is an agent
53
+ * typing near a credential.
54
+ */
55
+ export declare function classifyHumanRequired(signals: BrowserPageSignals, options?: BrowserHumanClassifierOptions): BrowserHumanRequiredReason | undefined;
56
+ /** What the host read about one field before typing into it. */
57
+ export interface BrowserFieldFacts {
58
+ readonly tag: string;
59
+ readonly type: string;
60
+ readonly autocomplete: string;
61
+ readonly name: string;
62
+ readonly id: string;
63
+ readonly label: string;
64
+ }
65
+ /**
66
+ * Is this field a password or a one-time code? Typing into one is always
67
+ * refused, whatever the gate allowed: the agent never handles a credential.
68
+ */
69
+ export declare function isCredentialField(field: BrowserFieldFacts): boolean;
70
+ //# sourceMappingURL=classifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../src/classifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAE5D;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,gCAAgC;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,oEAAoE;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,kFAAkF;IAClF,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,sFAAsF;IACtF,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAClC,mFAAmF;IACnF,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CACrC;AAED,MAAM,WAAW,6BAA6B;IAC7C;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5C;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAQ9C,CAAA;AAWD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAOhD,CAAA;AA6CD,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOxD;AAED,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGtD;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,6BAAkC,GACzC,OAAO,CAMT;AASD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,GAAE,6BAAkC,GACzC,0BAA0B,GAAG,SAAS,CAOxC;AAED,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACtB;AAKD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAMnE"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Hosts and host/path prefixes that are a sign-in wherever they appear. The
3
+ * path forms below catch the rest (`/login`, `/signin`, `/sso`, …).
4
+ */
5
+ export const SIGN_IN_ADDRESSES = [
6
+ 'accounts.google.com',
7
+ 'login.microsoftonline.com',
8
+ 'login.live.com',
9
+ 'appleid.apple.com',
10
+ 'github.com/login',
11
+ 'github.com/session',
12
+ 'gitlab.com/users/sign_in',
13
+ ];
14
+ /** Second-factor addresses: a sign-in that is already half done. */
15
+ const TWO_FACTOR_ADDRESSES = ['github.com/sessions/two-factor'];
16
+ /** A path segment that is a sign-in page. `/author` is not `/auth`. */
17
+ const SIGN_IN_PATH = /(?:^|\/)(?:login|log-in|signin|sign-in|sign_in|auth|sso|oauth2?\/authorize|authorize)(?:\/|\.[a-z]+$|$)/i;
18
+ const TWO_FACTOR_PATH = /(?:^|\/)(?:two-factor|2fa|mfa|otp|totp)(?:\/|\.[a-z]+$|$)/i;
19
+ /**
20
+ * Hosts that draw CAPTCHA and bot-check widgets in a frame. A frame served
21
+ * from one of these (or a subdomain) is a challenge.
22
+ */
23
+ export const CAPTCHA_FRAME_HOSTS = [
24
+ 'challenges.cloudflare.com',
25
+ 'hcaptcha.com',
26
+ 'newassets.hcaptcha.com',
27
+ 'arkoselabs.com',
28
+ 'funcaptcha.com',
29
+ 'recaptcha.net',
30
+ ];
31
+ /** reCAPTCHA is served from google.com under this path. */
32
+ const RECAPTCHA_PATH = /^\/recaptcha\//;
33
+ /**
34
+ * Titles of interstitial bot checks and blocks. Anchored and short on
35
+ * purpose: a page ABOUT access control must not match.
36
+ */
37
+ const BOT_BLOCK_TITLES = [
38
+ /^just a moment\.{0,3}$/i,
39
+ /^attention required!?(?: \| cloudflare)?$/i,
40
+ /^access denied$/i,
41
+ /^are you a robot\??$/i,
42
+ /^verify(?:ing)? (?:you are|that you are) (?:a )?human\.{0,3}$/i,
43
+ /^(?:security|human) (?:check|verification)$/i,
44
+ /^checking (?:your browser|if the site connection is secure)[\s\S]{0,40}$/i,
45
+ /^pardon our interruption\.{0,3}$/i,
46
+ /^please verify you are a human$/i,
47
+ /^one more step$/i,
48
+ /^robot check$/i,
49
+ /^ddos-guard$/i,
50
+ ];
51
+ function hostMatches(host, entry) {
52
+ return host === entry || host.endsWith(`.${entry}`);
53
+ }
54
+ function addressMatches(url, entry) {
55
+ const slash = entry.indexOf('/');
56
+ const host = (slash === -1 ? entry : entry.slice(0, slash)).toLowerCase();
57
+ const path = slash === -1 ? '' : entry.slice(slash);
58
+ if (url.hostname !== host)
59
+ return false;
60
+ if (path === '')
61
+ return true;
62
+ return url.pathname === path || url.pathname.startsWith(path.endsWith('/') ? path : `${path}/`);
63
+ }
64
+ function parse(raw) {
65
+ try {
66
+ return new URL(raw);
67
+ }
68
+ catch {
69
+ return undefined;
70
+ }
71
+ }
72
+ /** Is `frameUrl` a CAPTCHA or bot-check widget? Invisible-badge frames are not. */
73
+ export function isCaptchaFrame(frameUrl) {
74
+ const url = parse(frameUrl);
75
+ if (!url || (url.protocol !== 'https:' && url.protocol !== 'http:'))
76
+ return false;
77
+ if (url.searchParams.get('size') === 'invisible')
78
+ return false;
79
+ const host = url.hostname;
80
+ if (CAPTCHA_FRAME_HOSTS.some((entry) => hostMatches(host, entry)))
81
+ return true;
82
+ return (host === 'www.google.com' || host === 'google.com') && RECAPTCHA_PATH.test(url.pathname);
83
+ }
84
+ /** Is `title` the title of a bot check or block page? */
85
+ export function isBotBlockTitle(title) {
86
+ const flat = title.replace(/\s+/g, ' ').trim();
87
+ return BOT_BLOCK_TITLES.some((pattern) => pattern.test(flat));
88
+ }
89
+ /** Is `rawUrl` a sign-in address, by host list or by path? */
90
+ export function isSignInAddress(rawUrl, options = {}) {
91
+ const url = parse(rawUrl);
92
+ if (!url || (url.protocol !== 'https:' && url.protocol !== 'http:'))
93
+ return false;
94
+ const entries = [...SIGN_IN_ADDRESSES, ...(options.signInAddresses ?? [])];
95
+ if (entries.some((entry) => addressMatches(url, entry)))
96
+ return true;
97
+ return SIGN_IN_PATH.test(url.pathname);
98
+ }
99
+ function isTwoFactorAddress(rawUrl) {
100
+ const url = parse(rawUrl);
101
+ if (!url)
102
+ return false;
103
+ if (TWO_FACTOR_ADDRESSES.some((entry) => addressMatches(url, entry)))
104
+ return true;
105
+ return TWO_FACTOR_PATH.test(url.pathname);
106
+ }
107
+ /**
108
+ * Does the page need a person, and why? `undefined` when it does not.
109
+ *
110
+ * Order matters only for the reason reported: an HTTP credential prompt,
111
+ * then a CAPTCHA, a bot wall, a second factor, and last a sign-in. All of it
112
+ * is read by the host; nothing the model says reaches this function.
113
+ *
114
+ * It errs toward stopping. A page with a visible password box is treated as
115
+ * a sign-in even when it is a settings page, because the cost of a false stop
116
+ * is a question to the operator and the cost of a false pass is an agent
117
+ * typing near a credential.
118
+ */
119
+ export function classifyHumanRequired(signals, options = {}) {
120
+ if (signals.status === 401 || signals.status === 407)
121
+ return 'http-auth';
122
+ if (signals.frameUrls.some(isCaptchaFrame))
123
+ return 'captcha';
124
+ if (isBotBlockTitle(signals.title))
125
+ return 'bot-block';
126
+ if (signals.oneTimeCodeFields > 0 || isTwoFactorAddress(signals.url))
127
+ return 'two-factor';
128
+ if (signals.passwordFields > 0 || isSignInAddress(signals.url, options))
129
+ return 'sign-in';
130
+ return undefined;
131
+ }
132
+ const ONE_TIME_CODE_NAME = /(?:^|[^a-z])(?:otp|totp|2fa|mfa|one[-_ ]?time[-_ ]?(?:code|password)|verification[-_ ]?code|passcode|security[-_ ]?code|auth(?:entication)?[-_ ]?code)(?:[^a-z]|$)/i;
133
+ /**
134
+ * Is this field a password or a one-time code? Typing into one is always
135
+ * refused, whatever the gate allowed: the agent never handles a credential.
136
+ */
137
+ export function isCredentialField(field) {
138
+ if (field.tag !== 'input' && field.tag !== 'textarea')
139
+ return false;
140
+ if (field.type.toLowerCase() === 'password')
141
+ return true;
142
+ const autocomplete = field.autocomplete.toLowerCase();
143
+ if (/\b(?:current-password|new-password|one-time-code)\b/.test(autocomplete))
144
+ return true;
145
+ return [field.name, field.id, field.label].some((value) => ONE_TIME_CODE_NAME.test(value));
146
+ }
147
+ //# sourceMappingURL=classifier.js.map
@@ -0,0 +1 @@
1
+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E,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;AAC3F,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { type WslNetworkingMode } from './wsl.js';
2
+ /**
3
+ * Which browser runs, where, and whether its window is shown — decided from
4
+ * the environment before anything is launched.
5
+ *
6
+ * | Where namzu runs | Plan |
7
+ * | --- | --- |
8
+ * | WSL2 with interop and a Windows Chrome or Edge | `windows-cdp` — the Windows browser, driven over CDP |
9
+ * | WSL2 without either | `local` Chromium inside WSL (a warning says why); headed through WSLg when there is a display |
10
+ * | Linux with a display | `local`: Google Chrome if installed, else Playwright's Chromium |
11
+ * | Linux without a display | `local`, headless only |
12
+ * | macOS | `local`: Google Chrome if installed, else Playwright's Chromium |
13
+ * | Windows | `local`: Chrome, else Edge, else Playwright's Chromium |
14
+ *
15
+ * The `windows-cdp` engine starts the Windows browser through `powershell.exe`
16
+ * and talks CDP to it through that process's standard streams (see
17
+ * `windows-bridge.ts`), because WSL's NAT networking cannot reach Windows'
18
+ * `127.0.0.1`. Under mirrored networking it connects directly and keeps the
19
+ * bridge only to start and stop the browser.
20
+ */
21
+ /** `auto` follows the table; `windows` and `local` force one engine. */
22
+ export type BrowserEngineSetting = 'auto' | 'windows' | 'local';
23
+ /** `auto`: a window when there is a display and a person at it (`interactive`). */
24
+ export type BrowserHeadlessSetting = 'auto' | 'always' | 'never';
25
+ /** `interactive`: a person is at the terminal. `unattended`: a scheduled run. */
26
+ export type BrowserRunMode = 'interactive' | 'unattended';
27
+ export type BrowserHostPlatform = 'linux' | 'wsl' | 'darwin' | 'win32';
28
+ /** The file-system questions detection asks; injected so tests need no real machine. */
29
+ export interface BrowserEnvironmentProbes {
30
+ exists(path: string): boolean;
31
+ /** The file's text, or `undefined` if it cannot be read. */
32
+ readFile(path: string): string | undefined;
33
+ /** Entry names, or `[]` if the directory cannot be read. */
34
+ listDir(path: string): readonly string[];
35
+ /** Modification time in ms, or `undefined`. Absent: every file is equally old. */
36
+ modifiedMs?(path: string): number | undefined;
37
+ /**
38
+ * Standard output of a short-lived program, or `undefined` if it failed.
39
+ * Absent: nothing is run (`wslinfo` is skipped and `.wslconfig` decides).
40
+ */
41
+ run?(file: string, args: readonly string[]): string | undefined;
42
+ }
43
+ export interface DetectBrowserEnvironmentOptions {
44
+ readonly engine?: BrowserEngineSetting;
45
+ readonly headless?: BrowserHeadlessSetting;
46
+ readonly mode?: BrowserRunMode;
47
+ /** Under WSL: which Windows browser to drive. Default Chrome, else Edge. */
48
+ readonly windowsBrowser?: 'chrome' | 'msedge';
49
+ }
50
+ /** A browser this process launches itself, with Playwright. */
51
+ export interface LocalBrowserPlan {
52
+ readonly engine: 'local';
53
+ readonly platform: BrowserHostPlatform;
54
+ /** `chromium` is Playwright's own build, from its browser cache. */
55
+ readonly browser: 'chrome' | 'msedge' | 'chromium';
56
+ /** The Playwright channel for an installed browser; absent for Playwright's Chromium. */
57
+ readonly channel?: 'chrome' | 'msedge';
58
+ readonly headless: boolean;
59
+ /** A display is available for a visible window. */
60
+ readonly display: boolean;
61
+ readonly warnings: readonly string[];
62
+ /** Present when this plan cannot run at all. */
63
+ readonly unavailableReason?: string;
64
+ }
65
+ /** The Windows browser, driven from WSL over CDP. */
66
+ export interface WindowsCdpBrowserPlan {
67
+ readonly engine: 'windows-cdp';
68
+ readonly platform: 'wsl';
69
+ readonly browser: 'chrome' | 'msedge';
70
+ /** The browser as WSL sees it (`/mnt/c/Program Files/…/chrome.exe`). */
71
+ readonly executable: string;
72
+ /** The browser as Windows sees it (`C:\Program Files\…\chrome.exe`). */
73
+ readonly windowsExecutable: string;
74
+ /** `powershell.exe`, absolute, as WSL sees it. */
75
+ readonly powershell: string;
76
+ /** Where the Windows drives are mounted, with a trailing slash (`/mnt/`). */
77
+ readonly mountRoot: string;
78
+ /** `mirrored` lets WSL reach Windows' `127.0.0.1` directly; anything else goes through the bridge. */
79
+ readonly networkingMode: WslNetworkingMode;
80
+ /**
81
+ * The interop socket to hand a Windows program as `WSL_INTEROP`, when this
82
+ * process has none of its own (a systemd service). Absent when the
83
+ * environment's `WSL_INTEROP` works.
84
+ */
85
+ readonly interopSocket?: string;
86
+ readonly headless: boolean;
87
+ readonly display: true;
88
+ readonly warnings: readonly string[];
89
+ readonly unavailableReason?: string;
90
+ /** What to run instead when this engine is unavailable and was not forced. */
91
+ readonly fallback?: LocalBrowserPlan;
92
+ }
93
+ export type BrowserEnginePlan = LocalBrowserPlan | WindowsCdpBrowserPlan;
94
+ /** Probes over the real file system. */
95
+ export declare const nodeBrowserProbes: BrowserEnvironmentProbes;
96
+ /**
97
+ * The VM's networking mode: `wslinfo --networking-mode` when WSL has it;
98
+ * otherwise the one `.wslconfig` under `C:\Users` (when exactly one user has
99
+ * one); otherwise `unknown`, which is treated as NAT.
100
+ */
101
+ export declare function wslNetworkingMode(probes: BrowserEnvironmentProbes, mountRoot?: string): WslNetworkingMode;
102
+ /**
103
+ * The interop socket to give a Windows program: the environment's
104
+ * `WSL_INTEROP` when it exists, else one under `/run/WSL`.
105
+ */
106
+ export declare function wslInteropSocket(env: NodeJS.ProcessEnv, probes: BrowserEnvironmentProbes): string | undefined;
107
+ /** Is this Linux kernel WSL's? The environment variables are absent under a systemd service. */
108
+ export declare function isWsl(env: NodeJS.ProcessEnv, probes: BrowserEnvironmentProbes): boolean;
109
+ /**
110
+ * Can this WSL process start Windows programs? The binfmt handler must be
111
+ * registered, and a socket must be reachable: `WSL_INTEROP`, or one under
112
+ * `/run/WSL` (all a systemd user service has).
113
+ */
114
+ export declare function wslInteropAvailable(env: NodeJS.ProcessEnv, probes: BrowserEnvironmentProbes): boolean;
115
+ /**
116
+ * The engine plan for this environment. Pure over its arguments: the
117
+ * environment, the platform, and the probes answer every question.
118
+ */
119
+ export declare function detectBrowserEnvironment(env: NodeJS.ProcessEnv, platform: NodeJS.Platform, probes?: BrowserEnvironmentProbes, options?: DetectBrowserEnvironmentOptions): BrowserEnginePlan;
120
+ /**
121
+ * The plan to actually run: the plan itself, or its fallback when it is
122
+ * unavailable and has one. Still possibly unavailable — check
123
+ * `unavailableReason`.
124
+ */
125
+ export declare function runnableBrowserPlan(plan: BrowserEnginePlan): BrowserEnginePlan;
126
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAEA,OAAO,EAGN,KAAK,iBAAiB,EAMtB,MAAM,UAAU,CAAA;AAEjB;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wEAAwE;AACxE,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAA;AAE/D,mFAAmF;AACnF,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEhE,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,YAAY,CAAA;AAEzD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEtE,wFAAwF;AACxF,MAAM,WAAW,wBAAwB;IACxC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1C,4DAA4D;IAC5D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;IACxC,kFAAkF;IAClF,UAAU,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC7C;;;OAGG;IACH,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAA;CAC/D;AAED,MAAM,WAAW,+BAA+B;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAA;IACtC,QAAQ,CAAC,QAAQ,CA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