@mercuryo-ai/agentbrowse 0.2.57 → 0.2.60

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 (72) hide show
  1. package/README.md +50 -56
  2. package/dist/command-name.js +1 -1
  3. package/dist/commands/act.d.ts.map +1 -1
  4. package/dist/commands/act.js +13 -5
  5. package/dist/commands/action-executor-helpers.d.ts.map +1 -1
  6. package/dist/commands/action-executor-helpers.js +10 -8
  7. package/dist/commands/click-activation-policy.d.ts.map +1 -1
  8. package/dist/commands/click-activation-policy.js +6 -2
  9. package/dist/commands/launch.d.ts +0 -1
  10. package/dist/commands/launch.d.ts.map +1 -1
  11. package/dist/commands/launch.js +2 -8
  12. package/dist/commands/observe-inventory.d.ts +5 -1
  13. package/dist/commands/observe-inventory.d.ts.map +1 -1
  14. package/dist/commands/observe-inventory.js +316 -5
  15. package/dist/commands/observe-persistence.d.ts.map +1 -1
  16. package/dist/commands/observe-persistence.js +2 -0
  17. package/dist/commands/observe-projection.d.ts +3 -2
  18. package/dist/commands/observe-projection.d.ts.map +1 -1
  19. package/dist/commands/observe-projection.js +1 -0
  20. package/dist/commands/observe-protected.d.ts +3 -1
  21. package/dist/commands/observe-protected.d.ts.map +1 -1
  22. package/dist/commands/observe-protected.js +23 -1
  23. package/dist/commands/observe-semantics.d.ts.map +1 -1
  24. package/dist/commands/observe-semantics.js +70 -0
  25. package/dist/commands/observe.d.ts +1 -0
  26. package/dist/commands/observe.d.ts.map +1 -1
  27. package/dist/commands/observe.js +4 -2
  28. package/dist/control-semantics.d.ts.map +1 -1
  29. package/dist/control-semantics.js +5 -0
  30. package/dist/date-value-normalization.d.ts +16 -0
  31. package/dist/date-value-normalization.d.ts.map +1 -0
  32. package/dist/date-value-normalization.js +117 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +5 -24
  35. package/dist/library.d.ts +3 -0
  36. package/dist/library.d.ts.map +1 -1
  37. package/dist/library.js +2 -0
  38. package/dist/protected-fill.d.ts +3 -2
  39. package/dist/protected-fill.d.ts.map +1 -1
  40. package/dist/runtime-protected-state.d.ts.map +1 -1
  41. package/dist/runtime-protected-state.js +8 -1
  42. package/dist/runtime-state.d.ts +11 -0
  43. package/dist/runtime-state.d.ts.map +1 -1
  44. package/dist/secrets/form-matcher.d.ts +1 -2
  45. package/dist/secrets/form-matcher.d.ts.map +1 -1
  46. package/dist/secrets/form-matcher.js +125 -119
  47. package/dist/secrets/matching-helpers.d.ts +13 -0
  48. package/dist/secrets/matching-helpers.d.ts.map +1 -0
  49. package/dist/secrets/matching-helpers.js +147 -0
  50. package/dist/secrets/observed-field-resolution.d.ts +43 -0
  51. package/dist/secrets/observed-field-resolution.d.ts.map +1 -0
  52. package/dist/secrets/observed-field-resolution.js +223 -0
  53. package/dist/secrets/protected-field-semantics.d.ts.map +1 -1
  54. package/dist/secrets/protected-field-semantics.js +3 -2
  55. package/dist/secrets/protected-fill.d.ts +3 -1
  56. package/dist/secrets/protected-fill.d.ts.map +1 -1
  57. package/dist/secrets/protected-fill.js +31 -0
  58. package/dist/secrets/protected-value-adapters.d.ts.map +1 -1
  59. package/dist/secrets/protected-value-adapters.js +14 -22
  60. package/dist/secrets/types.d.ts +3 -0
  61. package/dist/secrets/types.d.ts.map +1 -1
  62. package/docs/README.md +15 -2
  63. package/docs/api-reference.md +13 -3
  64. package/docs/assistive-runtime.md +63 -7
  65. package/docs/configuration.md +16 -8
  66. package/docs/getting-started.md +17 -8
  67. package/docs/integration-checklist.md +8 -7
  68. package/docs/protected-fill.md +40 -7
  69. package/docs/testing.md +4 -3
  70. package/docs/troubleshooting.md +88 -34
  71. package/examples/README.md +9 -2
  72. package/package.json +8 -3
@@ -19,7 +19,19 @@ The normal flow is:
19
19
  5. `close(session)` ends the browser session
20
20
 
21
21
  The `session` is the key object in the whole API. It is the handle that keeps
22
- the browser connection and runtime state together between calls.
22
+ the browser connection and runtime state together between calls. A session
23
+ stays valid while the underlying browser connection is live; call
24
+ `status(session)` to check if you need to.
25
+
26
+ Refs returned by `observe(...)` (target refs, scope refs, fill refs) are
27
+ valid for the page state that produced them, not forever. Any of these
28
+ invalidates them:
29
+
30
+ - navigation to a different page;
31
+ - major DOM re-render (route change, modal open/close);
32
+ - an element removed by script.
33
+
34
+ After any of the above, call `observe(...)` again and use the new refs.
23
35
 
24
36
  At a high level, AgentBrowse has three kinds of behavior:
25
37
 
@@ -35,13 +47,10 @@ approval, secret, or payment logic.
35
47
 
36
48
  ## Managed Launch Note
37
49
 
38
- `launch(...)` uses a managed browser session. For that path, the package pulls
39
- in `puppeteer` for the stealth-enabled connection layer.
40
-
41
- This is there to reduce unnecessary captcha or anti-bot challenge pages during
42
- browser startup on sensitive sites.
43
-
44
- After launch, the normal page interaction flow still runs over Playwright CDP.
50
+ `launch(...)` starts a managed browser session. For that path, AgentBrowse
51
+ uses `puppeteer` with stealth evasions to reduce unnecessary captcha or
52
+ anti-bot challenge pages on sensitive sites. Page interaction then runs
53
+ through Playwright over CDP, which is what the rest of the API targets.
45
54
 
46
55
  ## Basic Example
47
56
 
@@ -1,7 +1,12 @@
1
1
  # AgentBrowse Integration Checklist
2
2
 
3
- Use this checklist when integrating the current `@mercuryo-ai/agentbrowse`
4
- contract into another package or service.
3
+ Checklist for engineers integrating `@mercuryo-ai/agentbrowse` into another
4
+ package or service. Use it as a final read-through before shipping an
5
+ integration.
6
+
7
+ > AgentBrowse is pre-1.0. Treat minor-version updates as potential
8
+ > behavior changes and re-run this checklist whenever you move to a newer
9
+ > release.
5
10
 
6
11
  ## Core Assumptions
7
12
 
@@ -28,9 +33,5 @@ contract into another package or service.
28
33
 
29
34
  - the root library entrypoint does not load `.env`
30
35
  - the CLI entrypoint is the only place that loads dotenv support
31
- - published examples and docs are part of the package contract
32
-
33
- ## Versioning Expectation
36
+ - published examples and docs are part of what consumers rely on
34
37
 
35
- AgentBrowse is still pre-1.0. Treat minor updates as contract-bearing changes
36
- and verify this checklist whenever you move to a newer release.
@@ -34,13 +34,19 @@ Use ordinary `act(..., 'fill', value)` when:
34
34
 
35
35
  Compared with a normal fill action, protected fill works with:
36
36
 
37
- - a previously observed `fillableForm`
38
- - structured `protectedValues` keyed by field meaning
39
- - optional `fieldPolicies`
40
- - typed execution outcomes
41
-
42
- It also validates that the previously observed form bindings still make sense
43
- before applying values.
37
+ - a `fillableForm` returned by a previous `observe(...)` call;
38
+ - structured `protectedValues` keyed by field meaning (e.g. `card_number`,
39
+ `password`), not by raw DOM selector;
40
+ - optional `fieldPolicies` that pin per-field behavior such as
41
+ `strict: true` (abort if the expected target is missing) or
42
+ `allowPartial: true` (apply what you can, skip the rest);
43
+ - typed execution outcomes so your code can distinguish success from
44
+ stale bindings, validation failure, and generic execution errors.
45
+
46
+ It also validates that the form bindings returned by `observe(...)` still
47
+ apply to the current DOM. If the page changed between observation and
48
+ fill, protected fill fails with a stale-binding result instead of trying
49
+ to fill a moved or removed target.
44
50
 
45
51
  ## Import
46
52
 
@@ -80,6 +86,33 @@ if (!result.success) {
80
86
  }
81
87
  ```
82
88
 
89
+ ### Form purpose values
90
+
91
+ `fillableForm.purpose` identifies which kind of form AgentBrowse detected.
92
+ The currently surfaced purposes are:
93
+
94
+ - `login` — username/password or email/password form.
95
+ - `identity` — identity-verification fields (name, address, document
96
+ details).
97
+ - `payment_card` — credit/debit card entry.
98
+ - `wallet` — crypto wallet address/chain fields.
99
+
100
+ ### Protected value keys
101
+
102
+ The keys in `protectedValues` are the standard field names chosen by the
103
+ form detector, not raw DOM attributes. Typical keys per purpose:
104
+
105
+ - `login`: `username`, `password` (or `email`, `password`).
106
+ - `identity`: `given_name`, `family_name`, `date_of_birth`, `country`,
107
+ `document_number`, etc.
108
+ - `payment_card`: `card_number`, `cardholder_name`, `exp_month`,
109
+ `exp_year`, `cvv`.
110
+ - `wallet`: `address`, `chain`.
111
+
112
+ The exact set of keys expected for a given `fillableForm` is listed in
113
+ `fillableForm.fields`. Always build `protectedValues` from that list rather
114
+ than assuming defaults.
115
+
83
116
  ## Where It Fits
84
117
 
85
118
  Protected fill handles the browser execution step.
package/docs/testing.md CHANGED
@@ -21,7 +21,8 @@ Use it when:
21
21
 
22
22
  - your tests wrap `extract(...)`
23
23
  - your tests cover goal-based `observe(session, goal)`
24
- - your package wants to exercise the current public assistive runtime contract
24
+ - your package wants to exercise the current public assistive runtime
25
+ shape
25
26
 
26
27
  ## Example
27
28
 
@@ -46,5 +47,5 @@ afterEach(() => {
46
47
 
47
48
  ## Scope
48
49
 
49
- This helper is for the assistive runtime contract. It does not mock browser
50
- sessions, pages, or observed target inventories.
50
+ This helper targets the assistive runtime only. It does not mock browser
51
+ sessions, pages, or observed targets.
@@ -1,71 +1,125 @@
1
1
  # AgentBrowse Troubleshooting
2
2
 
3
- ## Browser Does Not Launch Headful
3
+ Common failures and what to do about each.
4
4
 
5
- If `launch(...)` fails in a local GUI flow:
5
+ ## `launch(...)` Fails
6
6
 
7
- - confirm that Chrome or Chromium can start outside AgentBrowse
8
- - try `headless: true` to separate browser-launch problems from page problems
9
- - verify that the host has a usable display server if you expect a visible window
7
+ Most `launch(...)` failures come from the environment, not from AgentBrowse
8
+ itself:
10
9
 
11
- ## Why The Package Uses Both Puppeteer And Playwright
10
+ - **Missing or unreachable browser binary.** Confirm that Chrome or Chromium
11
+ starts outside AgentBrowse first.
12
+ - **No display server.** If you expect a visible window, verify the host
13
+ actually has one. To isolate launch-vs-page problems, retry with
14
+ `headless: true`.
15
+ - **Conflicting debug port.** If another Chrome instance is already
16
+ listening on the CDP port you need, the launch cannot bind.
17
+
18
+ Inspect the `error` and `reason` fields on the `launch(...)` failure result
19
+ (typed by `LAUNCH_ERROR_CODES`) before deciding whether to retry.
20
+
21
+ ## `attach(...)` Fails
22
+
23
+ - **Unreachable CDP WebSocket URL.** Verify the URL with a simple
24
+ WebSocket client or `curl`.
25
+ - **Session already owned.** Some providers reject a second CDP attach for
26
+ the same session.
27
+ - **Version mismatch.** Very old or very new Chrome versions may not match
28
+ Playwright's expected CDP shape; `status(session)` after attach returns
29
+ details in that case.
30
+
31
+ ## Browser Session Becomes Invalid
12
32
 
13
- `launch(...)` uses Puppeteer for the managed browser connection layer with
14
- stealth evasions enabled.
33
+ A `session` handle is valid only while the underlying browser connection
34
+ is live.
15
35
 
16
- After the browser is up, normal page interaction runs through Playwright CDP.
36
+ - If the browser process died, the next `act(...)` / `observe(...)` call
37
+ will fail with a connection error. Use `status(session)` to confirm, then
38
+ call `launch(...)` or `attach(...)` again.
39
+ - If you restored a session from `loadBrowserSession()` or a custom store,
40
+ call `status(session)` right after loading. If it reports the session is
41
+ no longer reachable, discard it and start fresh.
42
+ - `close(session)` called twice is safe — the second call is a no-op.
17
43
 
18
- That split exists to reduce unnecessary anti-bot friction during managed launch
19
- while keeping the live runtime on the Playwright side.
44
+ ## Why The Package Uses Both Puppeteer And Playwright
45
+
46
+ `launch(...)` uses Puppeteer with stealth evasions to connect to the
47
+ managed browser — this reduces unnecessary anti-bot friction on sensitive
48
+ sites. Live page interaction runs through Playwright over CDP, which is
49
+ what the rest of the API targets.
50
+
51
+ You do not need to know the split to use the library; it only matters when
52
+ a stack trace points at one runtime or the other.
20
53
 
21
54
  ## `observe(...)` Returned Zero Targets
22
55
 
23
56
  This usually means one of three things:
24
57
 
25
- - the page has not reached the state you expect yet
26
- - the goal was too narrow for the current page state
27
- - the page is mostly blocked by a gate, overlay, or challenge
58
+ - the page has not reached the state you expect yet;
59
+ - the goal was too narrow for the current page state;
60
+ - the page is mostly blocked by a gate, overlay, or challenge.
28
61
 
29
62
  What to do:
30
63
 
31
- - run `observe(session)` without a goal first
32
- - inspect `signals`
33
- - inspect `fillableForms`
34
- - check `status(session)` and current `url`
64
+ - run `observe(session)` without a goal first;
65
+ - inspect `signals` for notices, errors, or challenge messages;
66
+ - inspect `fillableForms` — there may be a form target without a clear goal
67
+ match;
68
+ - check `status(session)` and the current `url`.
35
69
 
36
70
  ## `act(...)` Fails With A Stale Or Missing Target
37
71
 
38
- Target refs are durable within the observed page state, not forever.
72
+ A `ref` returned by `observe(...)` is valid for the page state that
73
+ produced it, not forever. Any of these invalidates it:
39
74
 
40
- If the page rerendered, navigated, or replaced a surface, re-run `observe(...)`
41
- and use the new `ref` values.
75
+ - navigation to a different page;
76
+ - major DOM re-render (route change, modal open/close, framework patch);
77
+ - element removed by script.
78
+
79
+ After any of the above, call `observe(...)` again and use the new `ref`
80
+ values. `act(...)` failures from a stale ref surface as an error code in
81
+ `ACT_ERROR_CODES`; check the error field before retrying the same ref.
42
82
 
43
83
  ## Scoped `extract(...)` Fails With A Stale Scope
44
84
 
45
- `scopeRef` is tied to the observed scope binding that produced it.
85
+ `scopeRef` is tied to the observed scope that produced it. If the page
86
+ changed enough that the scope no longer maps cleanly, `extract(...)`
87
+ surfaces a stale-scope error.
46
88
 
47
- If the page changed enough that the scope no longer resolves cleanly, run
48
- `observe(...)` again and use the current `scopeRef`.
89
+ Run `observe(...)` again and use the fresh `scopeRef`.
49
90
 
50
91
  ## `extract(...)` Fails Immediately
51
92
 
52
93
  Two common causes:
53
94
 
54
- - no assistive runtime is configured
55
- - the schema input is invalid
95
+ - **No assistive runtime configured.** `extract(...)` calls an LLM through
96
+ the assistive runtime. Without one, the call fails with
97
+ `AgentbrowseAssistiveRuntimeMissingError`. See the
98
+ [Assistive Runtime Guide](./assistive-runtime.md).
99
+ - **Invalid schema input.** Valid inputs are a plain schema object
100
+ (`{ field: 'string' }`) or a Zod schema. Other shapes are rejected.
101
+
102
+ If the LLM returns a structured output that was cut off mid-response,
103
+ AgentBrowse throws `AssistiveStructuredOutputTruncatedError` — usually a
104
+ signal to increase the assistive-runtime token budget.
56
105
 
57
- Valid schema inputs are:
106
+ ## Protected Fill Reports Stale Bindings
58
107
 
59
- - a plain schema object
60
- - a Zod schema
108
+ `fillProtectedForm(...)` validates that the previously observed form
109
+ bindings still make sense. If the page changed between `observe(...)` and
110
+ `fillProtectedForm(...)`, the call returns a stale-binding failure. Re-run
111
+ `observe(...)`, find the updated `fillableForm`, and call
112
+ `fillProtectedForm(...)` again with the new reference.
61
113
 
62
114
  ## You Keep Hitting Captcha Or Anti-Bot Pages
63
115
 
64
- Managed `launch(...)` enables a stealth-oriented Puppeteer connection layer, but
65
- that only reduces unnecessary friction. It does not guarantee bypass.
116
+ Managed `launch(...)` enables a stealth-oriented Puppeteer connection
117
+ layer, but that only reduces unnecessary friction. It does not guarantee
118
+ bypass.
66
119
 
67
120
  If a site still gates the session:
68
121
 
69
- - retry with a normal local browser profile if your flow permits it
70
- - confirm that the site is reachable outside automation
71
- - treat the page as a site policy or anti-abuse boundary until proven otherwise
122
+ - retry with a normal local browser profile if your flow permits it;
123
+ - confirm that the site is reachable outside automation;
124
+ - treat the page as a site policy or anti-abuse boundary until proven
125
+ otherwise.
@@ -20,8 +20,15 @@ npx tsx examples/extract.ts
20
20
  Examples:
21
21
 
22
22
  - `basic.ts`
23
- Launches a managed browser, observes the page, and prints a small target summary.
23
+ Launches a managed browser, observes the page, and prints a small target
24
+ summary.
24
25
  - `attach.ts`
25
26
  Attaches to an existing CDP browser session.
26
27
  - `extract.ts`
27
- Runs structured extraction with an assistive runtime and a plain schema object.
28
+ Runs structured extraction with an assistive runtime and a plain schema
29
+ object.
30
+
31
+ For protected-fill usage (paying with a card, filling login credentials
32
+ from a user's vault), see [../docs/protected-fill.md](../docs/protected-fill.md).
33
+ The example in that guide is self-contained and uses the same `observe(...)` →
34
+ `fillProtectedForm(...)` pattern.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercuryo-ai/agentbrowse",
3
- "version": "0.2.57",
3
+ "version": "0.2.60",
4
4
  "type": "module",
5
5
  "description": "Browser automation primitives library for AI agents",
6
6
  "license": "MIT",
@@ -70,11 +70,16 @@
70
70
  "vitest": "^4.0.18"
71
71
  },
72
72
  "scripts": {
73
- "build": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true })\" && tsc -p tsconfig.build.json",
73
+ "build": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true, maxRetries: 10, retryDelay: 50 })\" && tsc -p tsconfig.build.json",
74
74
  "agentbrowse": "tsx src/index.ts",
75
- "test": "npm run test:unit && npm run test:e2e",
75
+ "test": "npm run test:full",
76
+ "test:full": "npm run test:unit && npm run test:e2e",
76
77
  "test:unit": "vitest run --exclude \"src/__tests__/*.e2e.test.ts\"",
77
78
  "test:e2e": "vitest run --no-file-parallelism --maxWorkers=1 src/__tests__/observe-stagehand.e2e.test.ts src/__tests__/extract.e2e.test.ts src/__tests__/runtime.e2e.test.ts",
79
+ "test:autonomous:scenarios": "npm run test:autonomous:scenarios:bare",
80
+ "test:autonomous:scenarios:bare": "vitest run --no-file-parallelism --maxWorkers=1 src/__tests__/runtime.e2e.test.ts src/commands/act-locator-resolution.test.ts src/secrets/form-matcher.contract.test.ts src/secrets/form-matcher.test.ts -t \"\\\\[S\"",
81
+ "test:e2e:autonomous": "npm run test:autonomous:scenarios",
82
+ "test:e2e:autonomous:bare": "npm run test:autonomous:scenarios:bare",
78
83
  "check-types": "tsc --noEmit",
79
84
  "lint": "biome check src docs README.md",
80
85
  "pack:verify": "node scripts/verify-pack-artifact.mjs",