web-agent-bridge 1.0.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 +21 -0
- package/README.ar.md +446 -0
- package/README.md +544 -0
- package/bin/cli.js +80 -0
- package/bin/wab.js +80 -0
- package/examples/bidi-agent.js +119 -0
- package/examples/puppeteer-agent.js +108 -0
- package/examples/vision-agent.js +159 -0
- package/package.json +67 -0
- package/public/css/styles.css +1235 -0
- package/public/dashboard.html +566 -0
- package/public/docs.html +582 -0
- package/public/index.html +306 -0
- package/public/login.html +81 -0
- package/public/register.html +94 -0
- package/script/ai-agent-bridge.js +1282 -0
- package/sdk/README.md +55 -0
- package/sdk/index.js +167 -0
- package/sdk/package.json +14 -0
- package/server/index.js +105 -0
- package/server/middleware/auth.js +44 -0
- package/server/models/adapters/index.js +33 -0
- package/server/models/adapters/mysql.js +183 -0
- package/server/models/adapters/postgresql.js +172 -0
- package/server/models/adapters/sqlite.js +7 -0
- package/server/models/db.js +205 -0
- package/server/routes/api.js +121 -0
- package/server/routes/auth.js +51 -0
- package/server/routes/license.js +51 -0
- package/server/ws.js +81 -0
package/public/docs.html
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Documentation — Web Agent Bridge</title>
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
9
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
|
10
|
+
<link rel="stylesheet" href="/css/styles.css">
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
|
|
14
|
+
<!-- NAVBAR -->
|
|
15
|
+
<nav class="navbar">
|
|
16
|
+
<div class="container">
|
|
17
|
+
<a href="/" class="navbar-brand">
|
|
18
|
+
<div class="brand-icon">⚡</div>
|
|
19
|
+
<span>WAB</span>
|
|
20
|
+
</a>
|
|
21
|
+
<ul class="navbar-links">
|
|
22
|
+
<li><a href="/#features">Features</a></li>
|
|
23
|
+
<li><a href="/#pricing">Pricing</a></li>
|
|
24
|
+
<li><a href="/docs" style="color:var(--text-primary);">Docs</a></li>
|
|
25
|
+
</ul>
|
|
26
|
+
<div class="navbar-actions">
|
|
27
|
+
<a href="/dashboard" class="btn btn-ghost">Dashboard</a>
|
|
28
|
+
<a href="/register" class="btn btn-primary btn-sm">Get Started</a>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<!-- DOCS LAYOUT -->
|
|
34
|
+
<div class="container">
|
|
35
|
+
<div class="docs-layout">
|
|
36
|
+
|
|
37
|
+
<!-- Sidebar -->
|
|
38
|
+
<aside class="docs-sidebar">
|
|
39
|
+
<ul>
|
|
40
|
+
<li><a href="#overview" class="active">Overview</a></li>
|
|
41
|
+
<li><a href="#quick-start">Quick Start</a></li>
|
|
42
|
+
<li><a href="#configuration">Configuration</a></li>
|
|
43
|
+
<li><a href="#permissions">Permissions</a></li>
|
|
44
|
+
<li><a href="#api-reference">API Reference</a></li>
|
|
45
|
+
<li><a href="#actions">Actions</a></li>
|
|
46
|
+
<li><a href="#events">Events</a></li>
|
|
47
|
+
<li><a href="#agent-guide">Agent Integration Guide</a></li>
|
|
48
|
+
<li><a href="#security">Security</a></li>
|
|
49
|
+
<li><a href="#examples">Examples</a></li>
|
|
50
|
+
<li><a href="#rest-api">REST API</a></li>
|
|
51
|
+
<li><a href="#faq">FAQ</a></li>
|
|
52
|
+
</ul>
|
|
53
|
+
</aside>
|
|
54
|
+
|
|
55
|
+
<!-- Content -->
|
|
56
|
+
<div class="docs-content">
|
|
57
|
+
|
|
58
|
+
<h2 id="overview">Overview</h2>
|
|
59
|
+
<p>
|
|
60
|
+
<strong>Web Agent Bridge (WAB)</strong> is an open-source middleware script that creates a standardized
|
|
61
|
+
interface between AI agents and websites. Instead of forcing AI agents to parse and guess DOM structures,
|
|
62
|
+
WAB provides a clean, documented command layer that agents can read and execute.
|
|
63
|
+
</p>
|
|
64
|
+
<p>
|
|
65
|
+
When a website includes the WAB script, it exposes a <code>window.AICommands</code> object that describes
|
|
66
|
+
all available actions, their parameters, and how to execute them. AI agents can discover these commands
|
|
67
|
+
instantly and interact with the site accurately and securely.
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
<h3>Key Concepts</h3>
|
|
71
|
+
<ul>
|
|
72
|
+
<li><strong>Bridge Script</strong> — The client-side JavaScript file added to websites</li>
|
|
73
|
+
<li><strong>Actions</strong> — Defined operations that AI agents can execute (click, fill, scroll, API call)</li>
|
|
74
|
+
<li><strong>Permissions</strong> — Granular controls over what agents are allowed to do</li>
|
|
75
|
+
<li><strong>License Key</strong> — Unique identifier that links a site to its WAB account</li>
|
|
76
|
+
<li><strong>Auto-Discovery</strong> — Automatic detection of interactive elements on the page</li>
|
|
77
|
+
</ul>
|
|
78
|
+
|
|
79
|
+
<h2 id="quick-start">Quick Start</h2>
|
|
80
|
+
<p>Get your website AI-ready in under 5 minutes.</p>
|
|
81
|
+
|
|
82
|
+
<h3>Step 1: Create an Account</h3>
|
|
83
|
+
<p>Sign up at <a href="/register">/register</a> and add your site from the dashboard. You'll receive a license key.</p>
|
|
84
|
+
|
|
85
|
+
<h3>Step 2: Add the Script</h3>
|
|
86
|
+
<p>Include this in your website's HTML:</p>
|
|
87
|
+
<div class="code-block">
|
|
88
|
+
<div class="code-header">
|
|
89
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
90
|
+
<span class="code-lang">HTML</span>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="code-body">
|
|
93
|
+
<pre><code><span class="cm"><!-- Web Agent Bridge Configuration --></span>
|
|
94
|
+
<script>
|
|
95
|
+
window.AIBridgeConfig = {
|
|
96
|
+
<span class="prop">licenseKey</span>: <span class="str">"WAB-XXXXX-XXXXX-XXXXX-XXXXX"</span>,
|
|
97
|
+
<span class="prop">agentPermissions</span>: {
|
|
98
|
+
<span class="prop">readContent</span>: <span class="bool">true</span>,
|
|
99
|
+
<span class="prop">click</span>: <span class="bool">true</span>,
|
|
100
|
+
<span class="prop">fillForms</span>: <span class="bool">true</span>,
|
|
101
|
+
<span class="prop">scroll</span>: <span class="bool">true</span>
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
</script>
|
|
105
|
+
<script src=<span class="str">"https://yourserver.com/script/ai-agent-bridge.js"</span>></script></code></pre>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<h3>Step 3: Verify</h3>
|
|
110
|
+
<p>Open your browser console and type <code>window.AICommands</code>. You should see the bridge object with discovered actions.</p>
|
|
111
|
+
|
|
112
|
+
<h2 id="configuration">Configuration</h2>
|
|
113
|
+
<p>The bridge is configured through the <code>window.AIBridgeConfig</code> object, which must be set before loading the script.</p>
|
|
114
|
+
|
|
115
|
+
<div class="code-block">
|
|
116
|
+
<div class="code-header">
|
|
117
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
118
|
+
<span class="code-lang">JavaScript — Full Configuration</span>
|
|
119
|
+
</div>
|
|
120
|
+
<div class="code-body">
|
|
121
|
+
<pre><code>window.AIBridgeConfig = {
|
|
122
|
+
<span class="cm">// License key from your dashboard</span>
|
|
123
|
+
<span class="prop">licenseKey</span>: <span class="str">"WAB-XXXXX-XXXXX-XXXXX-XXXXX"</span>,
|
|
124
|
+
|
|
125
|
+
<span class="cm">// Subscription tier (verified server-side)</span>
|
|
126
|
+
<span class="prop">subscriptionTier</span>: <span class="str">"free"</span>,
|
|
127
|
+
|
|
128
|
+
<span class="cm">// What AI agents are allowed to do</span>
|
|
129
|
+
<span class="prop">agentPermissions</span>: {
|
|
130
|
+
<span class="prop">readContent</span>: <span class="bool">true</span>, <span class="cm">// Read page text</span>
|
|
131
|
+
<span class="prop">click</span>: <span class="bool">true</span>, <span class="cm">// Click elements</span>
|
|
132
|
+
<span class="prop">fillForms</span>: <span class="bool">false</span>, <span class="cm">// Fill and submit forms</span>
|
|
133
|
+
<span class="prop">scroll</span>: <span class="bool">true</span>, <span class="cm">// Scroll the page</span>
|
|
134
|
+
<span class="prop">navigate</span>: <span class="bool">false</span>, <span class="cm">// Navigate between pages</span>
|
|
135
|
+
<span class="prop">apiAccess</span>: <span class="bool">false</span>, <span class="cm">// Call internal APIs (Pro+)</span>
|
|
136
|
+
<span class="prop">automatedLogin</span>: <span class="bool">false</span>, <span class="cm">// Automated login (Starter+)</span>
|
|
137
|
+
<span class="prop">extractData</span>: <span class="bool">false</span> <span class="cm">// Extract structured data (Pro+)</span>
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
<span class="cm">// Access restrictions</span>
|
|
141
|
+
<span class="prop">restrictions</span>: {
|
|
142
|
+
<span class="prop">allowedSelectors</span>: [], <span class="cm">// Empty = allow all</span>
|
|
143
|
+
<span class="prop">blockedSelectors</span>: [<span class="str">".private"</span>, <span class="str">"[data-private]"</span>],
|
|
144
|
+
<span class="prop">requireLoginForActions</span>: [<span class="str">"apiAccess"</span>],
|
|
145
|
+
<span class="prop">rateLimit</span>: { <span class="prop">maxCallsPerMinute</span>: <span class="num">60</span> }
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
<span class="cm">// Activity logging</span>
|
|
149
|
+
<span class="prop">logging</span>: {
|
|
150
|
+
<span class="prop">enabled</span>: <span class="bool">false</span>,
|
|
151
|
+
<span class="prop">level</span>: <span class="str">"basic"</span> <span class="cm">// "basic" or "detailed"</span>
|
|
152
|
+
}
|
|
153
|
+
};</code></pre>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<h2 id="permissions">Permissions</h2>
|
|
158
|
+
<p>Permissions control what AI agents can do on your site. Each permission can be independently toggled.</p>
|
|
159
|
+
|
|
160
|
+
<table style="margin-bottom:24px;">
|
|
161
|
+
<thead>
|
|
162
|
+
<tr><th>Permission</th><th>Description</th><th>Min Tier</th></tr>
|
|
163
|
+
</thead>
|
|
164
|
+
<tbody>
|
|
165
|
+
<tr><td><code>readContent</code></td><td>Read text content from page elements</td><td>Free</td></tr>
|
|
166
|
+
<tr><td><code>click</code></td><td>Click buttons, links, and interactive elements</td><td>Free</td></tr>
|
|
167
|
+
<tr><td><code>scroll</code></td><td>Scroll the page or to specific elements</td><td>Free</td></tr>
|
|
168
|
+
<tr><td><code>fillForms</code></td><td>Fill form fields and submit forms</td><td>Free</td></tr>
|
|
169
|
+
<tr><td><code>navigate</code></td><td>Navigate to different pages</td><td>Free</td></tr>
|
|
170
|
+
<tr><td><code>automatedLogin</code></td><td>Perform automated login flows</td><td>Starter</td></tr>
|
|
171
|
+
<tr><td><code>apiAccess</code></td><td>Call internal REST API endpoints</td><td>Pro</td></tr>
|
|
172
|
+
<tr><td><code>extractData</code></td><td>Extract structured data from the page</td><td>Pro</td></tr>
|
|
173
|
+
</tbody>
|
|
174
|
+
</table>
|
|
175
|
+
|
|
176
|
+
<h2 id="api-reference">API Reference</h2>
|
|
177
|
+
<p>The <code>window.AICommands</code> object provides the following methods:</p>
|
|
178
|
+
|
|
179
|
+
<h3><code>getActions(category?)</code></h3>
|
|
180
|
+
<p>Returns an array of all available actions. Optionally filter by category.</p>
|
|
181
|
+
<div class="code-block">
|
|
182
|
+
<div class="code-header">
|
|
183
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
184
|
+
<span class="code-lang">JavaScript</span>
|
|
185
|
+
</div>
|
|
186
|
+
<div class="code-body">
|
|
187
|
+
<pre><code><span class="kw">const</span> allActions = window.AICommands.<span class="fn">getActions</span>();
|
|
188
|
+
<span class="kw">const</span> navActions = window.AICommands.<span class="fn">getActions</span>(<span class="str">"navigation"</span>);
|
|
189
|
+
|
|
190
|
+
<span class="cm">// Returns: [{ name, description, trigger, category, requiresAuth, params, fields }]</span></code></pre>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<h3><code>execute(actionName, params?)</code></h3>
|
|
195
|
+
<p>Execute a registered action. Returns a Promise with the result.</p>
|
|
196
|
+
<div class="code-block">
|
|
197
|
+
<div class="code-header">
|
|
198
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
199
|
+
<span class="code-lang">JavaScript</span>
|
|
200
|
+
</div>
|
|
201
|
+
<div class="code-body">
|
|
202
|
+
<pre><code><span class="kw">const</span> result = <span class="kw">await</span> window.AICommands.<span class="fn">execute</span>(<span class="str">"signup"</span>);
|
|
203
|
+
<span class="cm">// → { success: true, action: "click", selector: "#signup-button" }</span>
|
|
204
|
+
|
|
205
|
+
<span class="kw">const</span> formResult = <span class="kw">await</span> window.AICommands.<span class="fn">execute</span>(<span class="str">"fill_contact_form"</span>, {
|
|
206
|
+
<span class="prop">name</span>: <span class="str">"Alice"</span>,
|
|
207
|
+
<span class="prop">email</span>: <span class="str">"alice@example.com"</span>
|
|
208
|
+
});
|
|
209
|
+
<span class="cm">// → { success: true, results: [...] }</span></code></pre>
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
<h3><code>readContent(selector)</code></h3>
|
|
214
|
+
<p>Read text content from a DOM element.</p>
|
|
215
|
+
<div class="code-block">
|
|
216
|
+
<div class="code-header">
|
|
217
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
218
|
+
<span class="code-lang">JavaScript</span>
|
|
219
|
+
</div>
|
|
220
|
+
<div class="code-body">
|
|
221
|
+
<pre><code><span class="kw">const</span> content = window.AICommands.<span class="fn">readContent</span>(<span class="str">"h1.title"</span>);
|
|
222
|
+
<span class="cm">// → { success: true, text: "Welcome!", html: "Welcome!", attributes: {...} }</span></code></pre>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
|
|
226
|
+
<h3><code>getPageInfo()</code></h3>
|
|
227
|
+
<p>Get metadata about the current page and bridge state.</p>
|
|
228
|
+
<div class="code-block">
|
|
229
|
+
<div class="code-header">
|
|
230
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
231
|
+
<span class="code-lang">JavaScript</span>
|
|
232
|
+
</div>
|
|
233
|
+
<div class="code-body">
|
|
234
|
+
<pre><code><span class="kw">const</span> info = window.AICommands.<span class="fn">getPageInfo</span>();
|
|
235
|
+
<span class="cm">// → { title, url, domain, lang, bridgeVersion, tier, permissions, actionsCount, rateLimitRemaining }</span></code></pre>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
|
|
239
|
+
<h3><code>waitForElement(selector, timeout?)</code></h3>
|
|
240
|
+
<p>Wait for a DOM element to appear. Useful for SPAs and dynamically loaded content.</p>
|
|
241
|
+
<div class="code-block">
|
|
242
|
+
<div class="code-header">
|
|
243
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
244
|
+
<span class="code-lang">JavaScript</span>
|
|
245
|
+
</div>
|
|
246
|
+
<div class="code-body">
|
|
247
|
+
<pre><code><span class="kw">await</span> window.AICommands.<span class="fn">waitForElement</span>(<span class="str">".results-loaded"</span>, <span class="num">15000</span>);
|
|
248
|
+
<span class="cm">// Resolves when the element appears, rejects on timeout</span></code></pre>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
|
|
252
|
+
<h3><code>registerAction(actionDef)</code></h3>
|
|
253
|
+
<p>Register a custom action that AI agents can discover and execute.</p>
|
|
254
|
+
<div class="code-block">
|
|
255
|
+
<div class="code-header">
|
|
256
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
257
|
+
<span class="code-lang">JavaScript</span>
|
|
258
|
+
</div>
|
|
259
|
+
<div class="code-body">
|
|
260
|
+
<pre><code>window.AICommands.<span class="fn">registerAction</span>({
|
|
261
|
+
<span class="prop">name</span>: <span class="str">"addToCart"</span>,
|
|
262
|
+
<span class="prop">description</span>: <span class="str">"Add the current product to cart"</span>,
|
|
263
|
+
<span class="prop">trigger</span>: <span class="str">"click"</span>,
|
|
264
|
+
<span class="prop">selector</span>: <span class="str">"#add-to-cart-btn"</span>,
|
|
265
|
+
<span class="prop">category</span>: <span class="str">"e-commerce"</span>,
|
|
266
|
+
<span class="prop">metadata</span>: { <span class="prop">requiresProduct</span>: <span class="bool">true</span> }
|
|
267
|
+
});</code></pre>
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
<h3><code>authenticate(agentKey, agentMeta?)</code></h3>
|
|
272
|
+
<p>Authenticate an AI agent to access restricted actions.</p>
|
|
273
|
+
|
|
274
|
+
<h3><code>refresh()</code></h3>
|
|
275
|
+
<p>Re-scan the page and rebuild the action registry. Call this after significant DOM changes.</p>
|
|
276
|
+
|
|
277
|
+
<h3><code>onReady(callback)</code></h3>
|
|
278
|
+
<p>Register a callback for when the bridge finishes initialization.</p>
|
|
279
|
+
|
|
280
|
+
<h2 id="actions">Actions</h2>
|
|
281
|
+
<p>Actions are the core building blocks of WAB. Each action has:</p>
|
|
282
|
+
<ul>
|
|
283
|
+
<li><code>name</code> — Unique identifier</li>
|
|
284
|
+
<li><code>description</code> — Human/AI readable description</li>
|
|
285
|
+
<li><code>trigger</code> — Type of action: <code>click</code>, <code>fill_and_submit</code>, <code>scroll</code>, <code>api</code></li>
|
|
286
|
+
<li><code>selector</code> — CSS selector of the target element</li>
|
|
287
|
+
<li><code>fields</code> — Array of form fields (for fill_and_submit actions)</li>
|
|
288
|
+
<li><code>category</code> — Grouping label</li>
|
|
289
|
+
<li><code>requiresAuth</code> — Whether agent authentication is needed</li>
|
|
290
|
+
</ul>
|
|
291
|
+
|
|
292
|
+
<h3>Action Types</h3>
|
|
293
|
+
<table style="margin-bottom:24px;">
|
|
294
|
+
<thead>
|
|
295
|
+
<tr><th>Trigger</th><th>Description</th><th>Permission</th></tr>
|
|
296
|
+
</thead>
|
|
297
|
+
<tbody>
|
|
298
|
+
<tr><td><code>click</code></td><td>Click on an element</td><td>click</td></tr>
|
|
299
|
+
<tr><td><code>fill_and_submit</code></td><td>Fill form fields and submit</td><td>fillForms</td></tr>
|
|
300
|
+
<tr><td><code>scroll</code></td><td>Scroll to an element or direction</td><td>scroll</td></tr>
|
|
301
|
+
<tr><td><code>api</code></td><td>Call an internal API endpoint</td><td>apiAccess</td></tr>
|
|
302
|
+
</tbody>
|
|
303
|
+
</table>
|
|
304
|
+
|
|
305
|
+
<h2 id="events">Events</h2>
|
|
306
|
+
<p>Subscribe to bridge events for monitoring and integration:</p>
|
|
307
|
+
<div class="code-block">
|
|
308
|
+
<div class="code-header">
|
|
309
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
310
|
+
<span class="code-lang">JavaScript</span>
|
|
311
|
+
</div>
|
|
312
|
+
<div class="code-body">
|
|
313
|
+
<pre><code><span class="kw">const</span> bridge = window.AICommands;
|
|
314
|
+
|
|
315
|
+
bridge.events.<span class="fn">on</span>(<span class="str">'ready'</span>, (data) => {
|
|
316
|
+
console.<span class="fn">log</span>(<span class="str">'Bridge ready'</span>, data.version);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
bridge.events.<span class="fn">on</span>(<span class="str">'action:before'</span>, ({ action, params }) => {
|
|
320
|
+
console.<span class="fn">log</span>(<span class="str">`Executing: ${action}`</span>);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
bridge.events.<span class="fn">on</span>(<span class="str">'action:after'</span>, ({ action, result }) => {
|
|
324
|
+
console.<span class="fn">log</span>(<span class="str">`Result: ${result.success}`</span>);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
bridge.events.<span class="fn">on</span>(<span class="str">'error'</span>, (err) => {
|
|
328
|
+
console.<span class="fn">error</span>(<span class="str">'Bridge error'</span>, err);
|
|
329
|
+
});</code></pre>
|
|
330
|
+
</div>
|
|
331
|
+
</div>
|
|
332
|
+
|
|
333
|
+
<p>Available events: <code>ready</code>, <code>action:before</code>, <code>action:after</code>, <code>action:registered</code>, <code>action:unregistered</code>, <code>agent:authenticate</code>, <code>error</code>, <code>refresh</code>, <code>destroy</code></p>
|
|
334
|
+
|
|
335
|
+
<h2 id="agent-guide">Agent Integration Guide</h2>
|
|
336
|
+
<p>If you're building an AI agent that interacts with websites, here's how to use WAB.</p>
|
|
337
|
+
|
|
338
|
+
<h3>Detecting WAB</h3>
|
|
339
|
+
<div class="code-block">
|
|
340
|
+
<div class="code-header">
|
|
341
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
342
|
+
<span class="code-lang">JavaScript — Agent Side</span>
|
|
343
|
+
</div>
|
|
344
|
+
<div class="code-body">
|
|
345
|
+
<pre><code><span class="cm">// Check if the site supports WAB</span>
|
|
346
|
+
<span class="kw">if</span> (window.AICommands) {
|
|
347
|
+
<span class="kw">const</span> info = window.AICommands.<span class="fn">getPageInfo</span>();
|
|
348
|
+
console.<span class="fn">log</span>(<span class="str">`WAB v${info.bridgeVersion} detected`</span>);
|
|
349
|
+
console.<span class="fn">log</span>(<span class="str">`${info.actionsCount} actions available`</span>);
|
|
350
|
+
console.<span class="fn">log</span>(<span class="str">`Tier: ${info.tier}`</span>);
|
|
351
|
+
} <span class="kw">else</span> {
|
|
352
|
+
console.<span class="fn">log</span>(<span class="str">'No WAB support — fall back to DOM parsing'</span>);
|
|
353
|
+
}</code></pre>
|
|
354
|
+
</div>
|
|
355
|
+
</div>
|
|
356
|
+
|
|
357
|
+
<h3>Discovering and Executing Actions</h3>
|
|
358
|
+
<div class="code-block">
|
|
359
|
+
<div class="code-header">
|
|
360
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
361
|
+
<span class="code-lang">JavaScript — Full Agent Workflow</span>
|
|
362
|
+
</div>
|
|
363
|
+
<div class="code-body">
|
|
364
|
+
<pre><code><span class="kw">async function</span> <span class="fn">agentWorkflow</span>() {
|
|
365
|
+
<span class="kw">const</span> bridge = window.AICommands;
|
|
366
|
+
|
|
367
|
+
<span class="cm">// 1. Authenticate (if needed)</span>
|
|
368
|
+
bridge.<span class="fn">authenticate</span>(<span class="str">"agent-key-123"</span>, {
|
|
369
|
+
<span class="prop">name</span>: <span class="str">"MyAssistant"</span>,
|
|
370
|
+
<span class="prop">version</span>: <span class="str">"2.0"</span>
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
<span class="cm">// 2. Discover available actions</span>
|
|
374
|
+
<span class="kw">const</span> actions = bridge.<span class="fn">getActions</span>();
|
|
375
|
+
|
|
376
|
+
<span class="cm">// 3. Find the action we need</span>
|
|
377
|
+
<span class="kw">const</span> loginAction = actions.<span class="fn">find</span>(a => a.name.<span class="fn">includes</span>(<span class="str">'login'</span>));
|
|
378
|
+
|
|
379
|
+
<span class="cm">// 4. Execute it</span>
|
|
380
|
+
<span class="kw">if</span> (loginAction) {
|
|
381
|
+
<span class="kw">const</span> result = <span class="kw">await</span> bridge.<span class="fn">execute</span>(loginAction.name, {
|
|
382
|
+
<span class="prop">email</span>: <span class="str">"user@example.com"</span>,
|
|
383
|
+
<span class="prop">password</span>: <span class="str">"secure-password"</span>
|
|
384
|
+
});
|
|
385
|
+
console.<span class="fn">log</span>(result);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
<span class="cm">// 5. Wait for navigation</span>
|
|
389
|
+
<span class="kw">await</span> bridge.<span class="fn">waitForNavigation</span>();
|
|
390
|
+
|
|
391
|
+
<span class="cm">// 6. Refresh actions for new page</span>
|
|
392
|
+
bridge.<span class="fn">refresh</span>();
|
|
393
|
+
}</code></pre>
|
|
394
|
+
</div>
|
|
395
|
+
</div>
|
|
396
|
+
|
|
397
|
+
<h2 id="security">Security</h2>
|
|
398
|
+
<p>WAB is built with security as a first-class concern:</p>
|
|
399
|
+
<ul>
|
|
400
|
+
<li><strong>Permission-based access</strong> — Site owners control exactly what agents can do</li>
|
|
401
|
+
<li><strong>Selector restrictions</strong> — Block sensitive areas of the page from agent interaction</li>
|
|
402
|
+
<li><strong>Rate limiting</strong> — Built-in protection against abuse</li>
|
|
403
|
+
<li><strong>Server-side license verification</strong> — Tier permissions are verified by the licensing server</li>
|
|
404
|
+
<li><strong>Agent authentication</strong> — Optional agent identity verification</li>
|
|
405
|
+
<li><strong>Opt-in only</strong> — Sites must explicitly add the script; users can disable via extensions</li>
|
|
406
|
+
</ul>
|
|
407
|
+
|
|
408
|
+
<h3>Best Practices</h3>
|
|
409
|
+
<ol>
|
|
410
|
+
<li>Always use <code>blockedSelectors</code> to protect sensitive areas (forms with credit cards, admin panels)</li>
|
|
411
|
+
<li>Start with minimal permissions and expand as needed</li>
|
|
412
|
+
<li>Enable logging to monitor agent behavior</li>
|
|
413
|
+
<li>Use the <code>requireLoginForActions</code> restriction for sensitive operations</li>
|
|
414
|
+
<li>Keep your license key confidential</li>
|
|
415
|
+
</ol>
|
|
416
|
+
|
|
417
|
+
<h2 id="examples">Examples</h2>
|
|
418
|
+
|
|
419
|
+
<h3>E-commerce Site</h3>
|
|
420
|
+
<div class="code-block">
|
|
421
|
+
<div class="code-header">
|
|
422
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
423
|
+
<span class="code-lang">JavaScript</span>
|
|
424
|
+
</div>
|
|
425
|
+
<div class="code-body">
|
|
426
|
+
<pre><code>window.AIBridgeConfig = {
|
|
427
|
+
<span class="prop">licenseKey</span>: <span class="str">"WAB-SHOP-XXXXX-XXXXX"</span>,
|
|
428
|
+
<span class="prop">agentPermissions</span>: {
|
|
429
|
+
<span class="prop">readContent</span>: <span class="bool">true</span>,
|
|
430
|
+
<span class="prop">click</span>: <span class="bool">true</span>,
|
|
431
|
+
<span class="prop">fillForms</span>: <span class="bool">true</span>,
|
|
432
|
+
<span class="prop">scroll</span>: <span class="bool">true</span>
|
|
433
|
+
},
|
|
434
|
+
<span class="prop">restrictions</span>: {
|
|
435
|
+
<span class="prop">blockedSelectors</span>: [<span class="str">"#checkout-payment"</span>, <span class="str">".credit-card-form"</span>],
|
|
436
|
+
<span class="prop">rateLimit</span>: { <span class="prop">maxCallsPerMinute</span>: <span class="num">30</span> }
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
<span class="cm">// After the bridge loads, add custom actions</span>
|
|
441
|
+
document.<span class="fn">addEventListener</span>(<span class="str">'wab:ready'</span>, () => {
|
|
442
|
+
window.AICommands.<span class="fn">registerAction</span>({
|
|
443
|
+
<span class="prop">name</span>: <span class="str">"searchProducts"</span>,
|
|
444
|
+
<span class="prop">description</span>: <span class="str">"Search for products by keyword"</span>,
|
|
445
|
+
<span class="prop">trigger</span>: <span class="str">"fill_and_submit"</span>,
|
|
446
|
+
<span class="prop">fields</span>: [{ <span class="prop">name</span>: <span class="str">"query"</span>, <span class="prop">selector</span>: <span class="str">"#search-input"</span>, <span class="prop">type</span>: <span class="str">"text"</span> }],
|
|
447
|
+
<span class="prop">submitSelector</span>: <span class="str">"#search-btn"</span>,
|
|
448
|
+
<span class="prop">category</span>: <span class="str">"search"</span>
|
|
449
|
+
});
|
|
450
|
+
});</code></pre>
|
|
451
|
+
</div>
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
<h3>SaaS Dashboard</h3>
|
|
455
|
+
<div class="code-block">
|
|
456
|
+
<div class="code-header">
|
|
457
|
+
<div class="code-dots"><span></span><span></span><span></span></div>
|
|
458
|
+
<span class="code-lang">JavaScript</span>
|
|
459
|
+
</div>
|
|
460
|
+
<div class="code-body">
|
|
461
|
+
<pre><code>window.AIBridgeConfig = {
|
|
462
|
+
<span class="prop">licenseKey</span>: <span class="str">"WAB-SAAS-XXXXX-XXXXX"</span>,
|
|
463
|
+
<span class="prop">subscriptionTier</span>: <span class="str">"pro"</span>,
|
|
464
|
+
<span class="prop">agentPermissions</span>: {
|
|
465
|
+
<span class="prop">readContent</span>: <span class="bool">true</span>,
|
|
466
|
+
<span class="prop">click</span>: <span class="bool">true</span>,
|
|
467
|
+
<span class="prop">fillForms</span>: <span class="bool">true</span>,
|
|
468
|
+
<span class="prop">apiAccess</span>: <span class="bool">true</span>,
|
|
469
|
+
<span class="prop">extractData</span>: <span class="bool">true</span>
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
document.<span class="fn">addEventListener</span>(<span class="str">'wab:ready'</span>, () => {
|
|
474
|
+
<span class="cm">// Custom API action</span>
|
|
475
|
+
window.AICommands.<span class="fn">registerAction</span>({
|
|
476
|
+
<span class="prop">name</span>: <span class="str">"getAnalytics"</span>,
|
|
477
|
+
<span class="prop">description</span>: <span class="str">"Fetch analytics data for the current period"</span>,
|
|
478
|
+
<span class="prop">trigger</span>: <span class="str">"api"</span>,
|
|
479
|
+
<span class="prop">endpoint</span>: <span class="str">"/api/analytics/current"</span>,
|
|
480
|
+
<span class="prop">method</span>: <span class="str">"GET"</span>,
|
|
481
|
+
<span class="prop">requiresAuth</span>: <span class="bool">true</span>,
|
|
482
|
+
<span class="prop">category</span>: <span class="str">"data"</span>
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
<span class="cm">// Custom handler action</span>
|
|
486
|
+
window.AICommands.<span class="fn">registerAction</span>({
|
|
487
|
+
<span class="prop">name</span>: <span class="str">"exportReport"</span>,
|
|
488
|
+
<span class="prop">description</span>: <span class="str">"Generate and download a PDF report"</span>,
|
|
489
|
+
<span class="prop">trigger</span>: <span class="str">"click"</span>,
|
|
490
|
+
<span class="prop">category</span>: <span class="str">"export"</span>,
|
|
491
|
+
<span class="prop">handler</span>: <span class="kw">async</span> () => {
|
|
492
|
+
<span class="kw">const</span> res = <span class="kw">await</span> <span class="fn">fetch</span>(<span class="str">'/api/report/generate'</span>);
|
|
493
|
+
<span class="kw">const</span> blob = <span class="kw">await</span> res.<span class="fn">blob</span>();
|
|
494
|
+
<span class="cm">// trigger download...</span>
|
|
495
|
+
<span class="kw">return</span> { <span class="prop">success</span>: <span class="bool">true</span>, <span class="prop">message</span>: <span class="str">"Report downloaded"</span> };
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
});</code></pre>
|
|
499
|
+
</div>
|
|
500
|
+
</div>
|
|
501
|
+
|
|
502
|
+
<h2 id="rest-api">REST API</h2>
|
|
503
|
+
<p>The WAB server provides a REST API for managing sites, licenses, and analytics.</p>
|
|
504
|
+
|
|
505
|
+
<h3>Authentication</h3>
|
|
506
|
+
<table style="margin-bottom:16px;">
|
|
507
|
+
<thead><tr><th>Endpoint</th><th>Method</th><th>Description</th></tr></thead>
|
|
508
|
+
<tbody>
|
|
509
|
+
<tr><td><code>POST /api/auth/register</code></td><td>POST</td><td>Create a new account</td></tr>
|
|
510
|
+
<tr><td><code>POST /api/auth/login</code></td><td>POST</td><td>Sign in and receive JWT token</td></tr>
|
|
511
|
+
<tr><td><code>GET /api/auth/me</code></td><td>GET</td><td>Get current user info</td></tr>
|
|
512
|
+
</tbody>
|
|
513
|
+
</table>
|
|
514
|
+
|
|
515
|
+
<h3>Sites</h3>
|
|
516
|
+
<table style="margin-bottom:16px;">
|
|
517
|
+
<thead><tr><th>Endpoint</th><th>Method</th><th>Description</th></tr></thead>
|
|
518
|
+
<tbody>
|
|
519
|
+
<tr><td><code>GET /api/sites</code></td><td>GET</td><td>List all your sites</td></tr>
|
|
520
|
+
<tr><td><code>POST /api/sites</code></td><td>POST</td><td>Add a new site</td></tr>
|
|
521
|
+
<tr><td><code>GET /api/sites/:id</code></td><td>GET</td><td>Get site details</td></tr>
|
|
522
|
+
<tr><td><code>PUT /api/sites/:id/config</code></td><td>PUT</td><td>Update site configuration</td></tr>
|
|
523
|
+
<tr><td><code>PUT /api/sites/:id/tier</code></td><td>PUT</td><td>Change subscription tier</td></tr>
|
|
524
|
+
<tr><td><code>DELETE /api/sites/:id</code></td><td>DELETE</td><td>Delete a site</td></tr>
|
|
525
|
+
<tr><td><code>GET /api/sites/:id/snippet</code></td><td>GET</td><td>Get install snippet</td></tr>
|
|
526
|
+
<tr><td><code>GET /api/sites/:id/analytics</code></td><td>GET</td><td>Get analytics data</td></tr>
|
|
527
|
+
</tbody>
|
|
528
|
+
</table>
|
|
529
|
+
|
|
530
|
+
<h3>License</h3>
|
|
531
|
+
<table style="margin-bottom:16px;">
|
|
532
|
+
<thead><tr><th>Endpoint</th><th>Method</th><th>Description</th></tr></thead>
|
|
533
|
+
<tbody>
|
|
534
|
+
<tr><td><code>POST /api/license/verify</code></td><td>POST</td><td>Verify a license key for a domain</td></tr>
|
|
535
|
+
<tr><td><code>POST /api/license/track</code></td><td>POST</td><td>Record an analytics event</td></tr>
|
|
536
|
+
</tbody>
|
|
537
|
+
</table>
|
|
538
|
+
|
|
539
|
+
<h2 id="faq">FAQ</h2>
|
|
540
|
+
|
|
541
|
+
<h3>Is WAB free to use?</h3>
|
|
542
|
+
<p>The core script is open source and free forever. Advanced features like API access, detailed analytics, and automated login require a paid subscription.</p>
|
|
543
|
+
|
|
544
|
+
<h3>Does WAB work with all AI agents?</h3>
|
|
545
|
+
<p>WAB works with any agent that can execute JavaScript in a browser context — including Selenium, Puppeteer, Playwright, browser extensions, and AI tools like OpenAI's Operator or Anthropic's Computer Use.</p>
|
|
546
|
+
|
|
547
|
+
<h3>What if my site is a SPA?</h3>
|
|
548
|
+
<p>Call <code>bridge.refresh()</code> after navigation events to re-scan for new elements. The <code>waitForElement()</code> method helps agents wait for dynamically loaded content.</p>
|
|
549
|
+
|
|
550
|
+
<h3>Can I use WAB without the licensing server?</h3>
|
|
551
|
+
<p>Yes. Without a license key, WAB runs in free-tier mode with all basic permissions. The licensing server only validates premium features.</p>
|
|
552
|
+
|
|
553
|
+
</div>
|
|
554
|
+
</div>
|
|
555
|
+
</div>
|
|
556
|
+
|
|
557
|
+
<!-- FOOTER -->
|
|
558
|
+
<footer class="footer" style="margin-top:48px;">
|
|
559
|
+
<div class="container">
|
|
560
|
+
<div class="footer-bottom" style="border-top:none; padding-top:0;">
|
|
561
|
+
<span>© 2026 Web Agent Bridge. MIT License.</span>
|
|
562
|
+
<a href="/" class="btn btn-ghost btn-sm">Back to Home</a>
|
|
563
|
+
</div>
|
|
564
|
+
</div>
|
|
565
|
+
</footer>
|
|
566
|
+
|
|
567
|
+
<script>
|
|
568
|
+
const links = document.querySelectorAll('.docs-sidebar a');
|
|
569
|
+
const observer = new IntersectionObserver((entries) => {
|
|
570
|
+
entries.forEach(entry => {
|
|
571
|
+
if (entry.isIntersecting) {
|
|
572
|
+
links.forEach(l => l.classList.remove('active'));
|
|
573
|
+
const match = document.querySelector(`.docs-sidebar a[href="#${entry.target.id}"]`);
|
|
574
|
+
if (match) match.classList.add('active');
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}, { rootMargin: '-80px 0px -70% 0px' });
|
|
578
|
+
|
|
579
|
+
document.querySelectorAll('.docs-content h2[id]').forEach(h => observer.observe(h));
|
|
580
|
+
</script>
|
|
581
|
+
</body>
|
|
582
|
+
</html>
|