h17-webpilot 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.
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 Hugo Palma
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # Human Browser
2
+
3
+ CDP-free browser automation with human-like behavior via Chrome extension + WebSocket.
4
+
5
+ Control Chromium through a WebSocket protocol. Any language can connect. Built-in human-like mouse movement, typing, scrolling, and trap detection. No Puppeteer, no Playwright, no debugging port, no `navigator.webdriver`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install webpilot
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### 1. Configure
16
+
17
+ ```bash
18
+ cp node_modules/webpilot/human-browser.config.example.js human-browser.config.js
19
+ ```
20
+
21
+ Edit `human-browser.config.js` — set your browser path:
22
+
23
+ ```javascript
24
+ module.exports = {
25
+ browser: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
26
+ // Linux: "/usr/bin/google-chrome"
27
+ // Windows: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
28
+ profile: "./profile",
29
+ port: 7331,
30
+ };
31
+ ```
32
+
33
+ ### 2. Start
34
+
35
+ ```bash
36
+ npx webpilot start
37
+ ```
38
+
39
+ ### 3. Connect
40
+
41
+ #### Interactive CLI
42
+
43
+ ```bash
44
+ npx webpilot
45
+ ```
46
+
47
+ ```
48
+ wp> go example.com
49
+ wp> discover
50
+ wp> click h1
51
+ wp> type #search hello world
52
+ wp> ss
53
+ ```
54
+
55
+ #### Node.js (programmatic)
56
+
57
+ ```javascript
58
+ const { startWithPage } = require('webpilot');
59
+
60
+ const { page } = await startWithPage();
61
+ await page.goto('https://example.com');
62
+ await page.humanClick('h1');
63
+ await page.humanType('Hello world', { selector: '#search' });
64
+ ```
65
+
66
+ #### Any language (WebSocket)
67
+
68
+ Connect to `ws://localhost:7331` and send JSON:
69
+
70
+ ```json
71
+ { "id": "1", "action": "tabs.navigate", "params": { "url": "https://example.com" } }
72
+ ```
73
+
74
+ ## CLI Reference
75
+
76
+ **Navigation:**
77
+ - `go <url>` — navigate (auto-adds `https://`)
78
+ - `reload` / `back` / `forward` — page navigation
79
+ - `sd [px] [selector]` — scroll down
80
+ - `su [px] [selector]` — scroll up
81
+
82
+ **Query:**
83
+ - `q <selector>` — find all matches with handle IDs
84
+ - `wait <selector>` — wait for selector to appear
85
+ - `discover` — list all interactive elements
86
+
87
+ **Interact:**
88
+ - `click <selector|handleId>` — human click (bezier cursor + safety checks)
89
+ - `type [selector] <text>` — human type (character-by-character with variance)
90
+ - `clear <selector>` — clear input field
91
+ - `focus <selector>` — focus element
92
+ - `key <name>` — key press (Enter, Tab, Escape...)
93
+
94
+ **Inspect:**
95
+ - `eval <js>` — evaluate JavaScript
96
+ - `title` / `url` / `html` — quick page info
97
+ - `ss` — screenshot (saves PNG to current directory)
98
+ - `box <selector>` — bounding box
99
+ - `cookies` — dump all cookies
100
+ - `frames` — list all frames
101
+
102
+ **Meta:**
103
+ - `.tabs` — list tabs (with 0-9 aliases)
104
+ - `.tab <n>` — switch active tab
105
+ - `.events` — toggle event display
106
+ - `.status` — connection info
107
+ - `.quit` — exit
108
+
109
+ **Raw mode:**
110
+ - `action.name {"key": "value"}` — any protocol command
111
+ - `{"id": "1", "action": "...", ...}` — raw WebSocket JSON
112
+
113
+ ## Programmatic API
114
+
115
+ ```javascript
116
+ const {
117
+ start, // Launch browser + WS server
118
+ startWithPage, // start + return BridgePage on first tab
119
+ connectToServer, // Connect to already-running server
120
+ loadConfig, // Load human-browser.config.js
121
+ BridgePage, // Page automation class
122
+ BridgeElement, // DOM element wrapper
123
+ BridgeKeyboard, // Keyboard input
124
+ BridgeCursor, // Mouse cursor with bezier movement
125
+ } = require('webpilot');
126
+ ```
127
+
128
+ ## Architecture
129
+
130
+ 1. Node.js server starts a local WebSocket bridge on port 7331
131
+ 2. Chromium launches with the extension loaded into a clean profile
132
+ 3. The extension connects to the WS bridge from its service worker
133
+ 4. Your code (any language) connects to the same WS endpoint
134
+ 5. Commands are relayed to the extension and executed in-page
135
+
136
+ The extension runs as a content script in Chrome's ISOLATED world. No CDP, no debugging protocol, no detectable automation flags.
137
+
138
+ ### Human Behavior
139
+
140
+ All `human.*` commands include:
141
+
142
+ - Bezier curve mouse movement with overshoot
143
+ - Randomized timing and typing cadence
144
+ - Scroll behavior with flick sub-scrolls and back-scroll variance
145
+ - 13-point honeypot/trap detection (aria-hidden, offsetParent, opacity, visibility, sub-pixel, bounding-box shift, class-name regex)
146
+ - Configurable `avoid` rules per-request and global
147
+
148
+ ### Safety Layer
149
+
150
+ `human.click` returns `{ clicked: false, reason: "..." }` instead of clicking unsafe elements:
151
+
152
+ - `aria-hidden` — screen reader hidden
153
+ - `honeypot-class` — trap class names (ghost, sr-only, visually-hidden, etc.)
154
+ - `opacity-zero` / `visibility-hidden` — invisible elements
155
+ - `sub-pixel` — elements smaller than 5x5px
156
+ - `element-shifted` — element moved during think time
157
+ - `no-bounding-box` / `element-disappeared` — element not in DOM
158
+
159
+ ## Protocol
160
+
161
+ Full WebSocket protocol specification: [`protocol/PROTOCOL.md`](protocol/PROTOCOL.md)
162
+
163
+ ## LLM Integration
164
+
165
+ For AI agents that need to browse the web: [`SKILLS.md`](SKILLS.md)
166
+
167
+ ## Go CLI
168
+
169
+ A compiled Go CLI is also available in `cli/` for users who prefer a standalone binary:
170
+
171
+ ```bash
172
+ cd cli && go build -o hb && ./hb
173
+ ```
174
+
175
+ ## License
176
+
177
+ Apache 2.0
package/SKILLS.md ADDED
@@ -0,0 +1,299 @@
1
+ ---
2
+ name: human-browser
3
+ description: Skill for LLM agents to browse the web through the Human Browser WebSocket protocol. Covers navigation, interaction, data extraction, and recovery.
4
+ ---
5
+
6
+ # Human Browser — LLM Navigation Skill
7
+
8
+ You control a real Chrome browser through WebSocket JSON messages (`ws://localhost:7331`). A Chrome extension receives your commands and executes them in-page with human-like behavior. You cannot see the page — you must look before every action.
9
+
10
+ ## Mental Model
11
+
12
+ You are **blind**. The browser is a room you navigate by touch. Before every action:
13
+
14
+ 1. **Look** — read the page (`dom.getHTML`, `dom.discoverElements`, `tabs.screenshot`)
15
+ 2. **Think** — pick the right element from what you actually saw
16
+ 3. **Act** — interact with it (`human.click`, `human.type`, `human.scroll`)
17
+ 4. **Verify** — confirm the action worked (re-read, check URL, wait for expected element)
18
+
19
+ Never guess selectors. Never assume page state. Always look first.
20
+
21
+ ## Wire Format
22
+
23
+ Every message you send:
24
+ ```json
25
+ { "id": "unique-id", "tabId": 123, "action": "action.name", "params": {} }
26
+ ```
27
+
28
+ Every response you receive:
29
+ ```json
30
+ { "id": "same-id", "result": { ... } }
31
+ ```
32
+
33
+ Or on error:
34
+ ```json
35
+ { "id": "same-id", "error": "message" }
36
+ ```
37
+
38
+ You may also receive unsolicited events:
39
+ ```json
40
+ { "type": "event", "event": "urlChanged", "data": { "tabId": 123, "url": "..." } }
41
+ { "type": "event", "event": "response", "data": { "url": "...", "status": 200, "tabId": 123 } }
42
+ ```
43
+
44
+ Always use a unique `id` per request. Always include `tabId` (get it from `tabs.list`).
45
+
46
+ ## Your Eyes
47
+
48
+ These are your tools for understanding the page. Use them constantly.
49
+
50
+ | Command | What it gives you | When to use |
51
+ |---------|-------------------|-------------|
52
+ | `dom.getHTML` | Full page HTML (title, url, html) | Understanding page structure, extracting data |
53
+ | `dom.discoverElements` | List of interactive elements with labels, roles, positions | Deciding what to click or type into |
54
+ | `dom.queryAllInfo` | Elements matching a selector with handleId, tag, id, class, text, label | Narrowing down from a known selector pattern |
55
+ | `tabs.screenshot` | Base64 PNG of the viewport | Visual debugging, understanding layout |
56
+ | `dom.findScrollable` | All scrollable containers with handleIds | Finding panels to scroll for more content |
57
+ | `dom.boundingBox` | Position and size of an element | Checking if element is visible/on-screen |
58
+
59
+ ### Looking strategy
60
+
61
+ 1. **First visit to a page**: Use `dom.getHTML` to understand the full structure. It returns raw HTML — parse it to find patterns, selectors, data attributes.
62
+ 2. **Before clicking**: Use `dom.discoverElements` to see what's interactive, or `dom.queryAllInfo` with a candidate selector to find your target.
63
+ 3. **After an action**: Use `dom.waitForSelector` on something you expect to appear, then look again to confirm.
64
+ 4. **When lost**: `tabs.screenshot` gives you a visual snapshot. `dom.getHTML` gives you the truth.
65
+
66
+ ## Your Hands
67
+
68
+ Two tiers of interaction commands exist. **Always prefer human commands.**
69
+
70
+ ### Human commands (safe — use these)
71
+
72
+ Human commands include bezier cursor movement, randomized timing, honeypot detection, and avoid-rule checking. They behave like a real person.
73
+
74
+ | Command | Purpose | Key params |
75
+ |---------|---------|------------|
76
+ | `human.click` | Click an element | `handleId` or `selector`, optional `avoid` |
77
+ | `human.type` | Type text character-by-character | `text`, optional `handleId`/`selector` |
78
+ | `human.scroll` | Scroll a panel or the page | `handleId`/`selector`, `direction` |
79
+ | `human.clearInput` | Focus + select-all + delete | `handleId` or `selector` |
80
+
81
+ ### Raw commands (direct — use only when you need precision)
82
+
83
+ | Command | Purpose |
84
+ |---------|---------|
85
+ | `dom.click` | Same pipeline as human.click (this IS the human pipeline) |
86
+ | `dom.type` | Direct text insertion, no per-character timing |
87
+ | `dom.keyPress` | Single key press (`Enter`, `Tab`, `Escape`, etc.) |
88
+ | `dom.keyDown` / `dom.keyUp` | Hold/release keys (for shortcuts like Ctrl+A) |
89
+ | `dom.scroll` | Direct scroll with exact pixel amount |
90
+ | `dom.focus` | Focus an element without clicking |
91
+ | `dom.setValue` | Set input value directly (for hidden fields, React state) |
92
+
93
+ ### The avoid parameter
94
+
95
+ All human commands accept `avoid` — rules for elements that should never be interacted with:
96
+
97
+ ```json
98
+ {
99
+ "avoid": {
100
+ "selectors": [".cookie-banner", "#popup-overlay"],
101
+ "classes": ["sponsored", "ad-slot"],
102
+ "ids": ["newsletter-signup"],
103
+ "attributes": { "data-ad": "*", "data-tracking": "*" }
104
+ }
105
+ }
106
+ ```
107
+
108
+ If a human command returns `{ "clicked": false, "reason": "..." }`, the element was unsafe. Reasons include: `avoided`, `aria-hidden`, `no-offsetParent`, `honeypot-class`, `opacity-zero`, `visibility-hidden`, `sub-pixel`, `no-bounding-box`, `element-disappeared`, `element-shifted`. **Respect these. Do not retry the same element.**
109
+
110
+ ## Navigation
111
+
112
+ ### Going to a page
113
+
114
+ ```json
115
+ { "id": "1", "action": "tabs.navigate", "params": { "url": "https://example.com" } }
116
+ ```
117
+
118
+ Then **wait for the page to load**:
119
+
120
+ ```json
121
+ { "id": "2", "action": "dom.waitForSelector", "params": { "selector": "body", "timeout": 10000 } }
122
+ ```
123
+
124
+ Better: wait for a specific element you expect on that page, not just `body`.
125
+
126
+ ### SPA navigation (clicking links instead of URL changes)
127
+
128
+ Many modern sites are single-page apps. Clicking a nav link doesn't trigger a full page load — it swaps content in-place. After clicking a link:
129
+
130
+ 1. Wait for expected content: `dom.waitForSelector` with a selector unique to the destination
131
+ 2. Do NOT rely on `urlChanged` events alone — the URL may update before content renders
132
+ 3. If content doesn't appear within timeout, re-read the page with `dom.getHTML`
133
+
134
+ ### Tab management
135
+
136
+ ```json
137
+ { "id": "1", "action": "tabs.list", "params": {} }
138
+ { "id": "2", "action": "tabs.create", "params": { "url": "https://example.com" } }
139
+ { "id": "3", "action": "tabs.activate", "params": {}, "tabId": 456 }
140
+ { "id": "4", "action": "tabs.close", "params": {}, "tabId": 456 }
141
+ ```
142
+
143
+ Always `tabs.list` first to get the `tabId` you need. Commands sent without `tabId` go to the active tab.
144
+
145
+ ## Recipes
146
+
147
+ ### Recipe: Fill and submit a search form
148
+
149
+ ```
150
+ 1. dom.getHTML → find the search input selector
151
+ 2. human.click { selector: "#search-input" } → focus the input
152
+ 3. human.type { text: "my query" } → type the search
153
+ 4. dom.keyPress { key: "Enter" } → submit
154
+ 5. dom.waitForSelector { selector: ".results" } → wait for results
155
+ 6. dom.getHTML → read results
156
+ ```
157
+
158
+ ### Recipe: Scroll through a list and collect items
159
+
160
+ ```
161
+ 1. dom.findScrollable → find scrollable panels
162
+ 2. dom.getHTML → read initial content
163
+ 3. human.scroll { handleId: "el_7", direction: "down" } → scroll down
164
+ 4. sleep 1-2s → let content render
165
+ 5. dom.getHTML → read new content
166
+ 6. Repeat 3-5 until you have enough or scroll stops moving
167
+ ```
168
+
169
+ Use `dom.scroll` return values (`before`, `after`) to detect when you've hit the bottom: if `before === after`, there's nothing more to scroll.
170
+
171
+ ### Recipe: Navigate a multi-page flow (e.g., checkout, wizard)
172
+
173
+ ```
174
+ 1. dom.getHTML → understand current step
175
+ 2. Fill in fields (human.click → human.type for each)
176
+ 3. human.click { selector: "button.next" } → advance
177
+ 4. dom.waitForSelector { selector: ".step-2" } → wait for next step
178
+ 5. dom.getHTML → understand new step
179
+ 6. Repeat until done
180
+ ```
181
+
182
+ ### Recipe: Handle a login form
183
+
184
+ ```
185
+ 1. dom.getHTML → find email/password fields
186
+ 2. human.click { selector: "#email" }
187
+ 3. human.type { text: "user@example.com" }
188
+ 4. human.click { selector: "#password" }
189
+ 5. human.type { text: "password123" }
190
+ 6. human.click { selector: "button[type='submit']" }
191
+ 7. dom.waitForSelector { selector: ".dashboard" } → wait for post-login page
192
+ ```
193
+
194
+ If the site uses 2FA or CAPTCHA, you'll need to detect that from the DOM and handle accordingly.
195
+
196
+ ### Recipe: Extract data from a detail page
197
+
198
+ ```
199
+ 1. dom.getHTML → get full page HTML
200
+ 2. Parse the HTML to find the data you need
201
+ 3. If data is in specific elements:
202
+ dom.queryAllInfo { selector: ".product-card" } → get handles + text summary
203
+ dom.elementHTML { handleId: "el_3" } → get full HTML of one card
204
+ 4. If data requires page JS globals (rare):
205
+ dom.evaluate { fn: "() => window.__DATA__" } → may fail on strict CSP sites
206
+ ```
207
+
208
+ Prefer `dom.getHTML` + `dom.elementHTML` over `dom.evaluate`. They work on all sites regardless of CSP.
209
+
210
+ ## Waiting
211
+
212
+ **This is the #1 source of failures.** Pages don't load instantly. SPAs swap content asynchronously. After every navigation or interaction that changes the page:
213
+
214
+ - **Use `dom.waitForSelector`** with a selector you expect to appear
215
+ - **Set a reasonable timeout** (5000-10000ms for navigation, 3000ms for in-page changes)
216
+ - **If the wait times out**, don't retry blindly — re-read the page with `dom.getHTML` to understand what actually happened
217
+
218
+ ```json
219
+ { "id": "1", "action": "dom.waitForSelector", "params": { "selector": ".results-loaded", "timeout": 8000 } }
220
+ ```
221
+
222
+ Do NOT use fixed sleeps as a substitute for `waitForSelector`. Fixed sleeps are for behavioral pacing (looking human), not for waiting on page state.
223
+
224
+ ## Recovery
225
+
226
+ Things go wrong. Handles go stale, pages redirect, elements disappear.
227
+
228
+ ### Stale handle
229
+
230
+ If a command returns an error about an invalid handleId, the element was garbage-collected or the page navigated. **Re-query the selector:**
231
+
232
+ ```
233
+ 1. dom.querySelector { selector: "the-same-selector" } → get fresh handleId
234
+ 2. Retry your action with the new handleId
235
+ ```
236
+
237
+ ### Unexpected page
238
+
239
+ If after clicking you end up somewhere unexpected:
240
+ 1. Check the URL: `dom.getHTML` returns `url` in its result
241
+ 2. If wrong page: `tabs.navigate` back, or click the browser back button via `dom.evaluate`
242
+ 3. If a popup/modal appeared: look for a close button, click it, then retry
243
+
244
+ ### Element blocked
245
+
246
+ If `human.click` returns `{ clicked: false }`:
247
+ - `reason: "avoided"` — your avoid rules blocked it. Check if the rules are too aggressive.
248
+ - `reason: "no-offsetParent"` or `sub-pixel` — element is hidden or off-screen. Scroll first.
249
+ - `reason: "honeypot-class"` — genuine trap. Do not click.
250
+ - `reason: "element-disappeared"` — re-query and retry.
251
+ - `reason: "element-shifted"` — page was still loading. Wait, then retry.
252
+
253
+ ### Timeout
254
+
255
+ If a command times out (30s default), the extension may be disconnected or the page is unresponsive.
256
+ 1. Try `tabs.list` — if it works, the extension is alive
257
+ 2. Try targeting a different tab or reloading: `tabs.reload`
258
+ 3. If nothing responds, the server or extension may need restart
259
+
260
+ ## Selector Strategy
261
+
262
+ **Never guess selectors.** Always derive them from what you see in `dom.getHTML` or `dom.discoverElements`.
263
+
264
+ Good selector sources (most to least stable):
265
+ 1. **IDs**: `#login-form` — unique, stable
266
+ 2. **Data attributes**: `[data-testid="submit"]`, `[aria-label="Search"]` — designed for automation
267
+ 3. **Semantic HTML**: `button[type="submit"]`, `input[name="email"]`, `nav a[href="/about"]`
268
+ 4. **Role attributes**: `[role="dialog"]`, `[role="navigation"]`
269
+ 5. **Structural**: `.header > nav > ul > li:first-child a` — fragile, use as last resort
270
+
271
+ Bad selectors (avoid these):
272
+ - Hashed class names (`.css-1a2b3c`, `.sc-bZQynM`) — change every build
273
+ - Deep structural paths — break on any DOM change
274
+ - Guessed/assumed selectors you haven't verified in the actual HTML
275
+
276
+ ### When you can't find a good selector
277
+
278
+ Use `dom.discoverElements` — it returns interactive elements with their labels, roles, and types. Pick from that list. Or use `dom.queryAllInfo` with a broad selector (like `button` or `a`) and filter by the `text` or `label` field.
279
+
280
+ ## CSP Compatibility
281
+
282
+ The extension runs in Chrome's ISOLATED world (content script context). Most commands are immune to Content Security Policy restrictions.
283
+
284
+ **Always works (CSP-safe):** `dom.getHTML`, `dom.querySelector*`, `dom.queryAllInfo`, `dom.elementHTML`, `dom.findScrollable`, `dom.discoverElements`, `human.*`, `tabs.*`, `cookies.*`, `frames.list`
285
+
286
+ **May fail on strict-CSP sites:** `dom.evaluate`, `dom.elementEvaluate` — these try MAIN world first, fall back to ISOLATED. When falling back, they can access the DOM but NOT page JavaScript globals.
287
+
288
+ If you need page globals (`window.__INITIAL_STATE__`) and the site has strict CSP, that data is not accessible. Extract from the rendered DOM instead.
289
+
290
+ CSP errors in the browser console are harmless — sites cannot detect them.
291
+
292
+ ## Do Not
293
+
294
+ - Do not guess selectors — always look at the page first
295
+ - Do not skip waiting after navigation — pages need time to render
296
+ - Do not retry a blocked click without understanding the reason
297
+ - Do not use `dom.evaluate` when `dom.getHTML` or `dom.elementHTML` would work
298
+ - Do not send commands without a `tabId` unless you're sure which tab is active
299
+ - Do not treat `human.click` returning `{ clicked: false }` as an error to force through — it's the extension protecting you