Proof of Concept โ An AI agent that can perform real actions inside a user's browser.
What if an AI chatbot could do more than just reply with text? What if it could actually click buttons, navigate pages, fill forms, and manipulate the DOM โ all from a simple chat conversation?
This project proves that's possible on the web, today, using nothing but a hidden communication protocol between a server-side AI and a lightweight JavaScript SDK.
| Capability | Status | How It Works |
|---|---|---|
| AI โ Browser Navigation | โ Working | AI tells the browser to window.location.href to a URL |
| AI โ Browser Alerts | โ Working | AI triggers native alert() dialogs with dynamic messages |
| AI โ Console Logging | โ Working | AI sends debug info to console.log() |
| AI โ DOM Manipulation | โ Working | AI updates any element's text/HTML by ID (calculator demo) |
| Multiple Actions in One Response | โ Working | AI can fire several browser actions from a single response |
| Custom Action Registration | โ Working | Developers can register any custom JS function as a "tool" |
| Hidden Protocol (User Never Sees JSON) | โ Working | Action tokens are embedded as HTML comments โ invisible to end users |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER'S BROWSER โ
โ โ
โ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Chat UI โ โโโถ โ AIWebAgent (JS SDK) โ โ
โ โ (clean text) โ โ โข Parses action tokens โ โ
โ โโโโโโโโโโโโโโโโโ โ โข Executes registered โ โ
โ โ JavaScript functions โ โ
โ โ โข Returns clean text for UI โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โฒ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP / SSE
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LARAVEL BACKEND (The Brain) โ
โ โ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ โ
โ โ LLM / AI โโโโถโ ClientActionTool (PHP) โ โ
โ โ (GPT, etc) โ โ โข NavigateToPage โ โ
โ โโโโโโโโโโโโโโ โ โข ShowAlert โ โ
โ โ โข (extensible via subclasses) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Key Trick: Hidden Action Tokens
The AI's response looks like this to the user:
"Sure! I'm navigating you to the product page now."
But the raw response actually contains:
Sure! I'm navigating you to the product page now.
<!-- CLIENT_ACTION_START {"action":"navigate","payload":{"url":"/products/iphone-15"}} CLIENT_ACTION_END -->
The hidden HTML comment is parsed by the JS SDK, which executes the action and strips the token before displaying the text. The user never sees the JSON.
experiment-001/
โโโ README.md โ You are here
โโโ Guideline.md โ Architecture spec & implementation guidelines
โ
โโโ app/Ai/Tools/ โ ๐ง Backend (Laravel)
โ โโโ ClientActionTool.php โ Abstract base class with dispatch() method
โ โโโ NavigateToPage.php โ Concrete tool: browser navigation
โ โโโ ShowAlert.php โ Concrete tool: browser alerts
โ
โโโ public/ โ ๐ Frontend
โโโ js/ai-browser-tools.js โ AIWebAgent SDK (vanilla JS, ~230 lines)
โโโ simulate.html โ Interactive test page with all demos
No backend required! The simulation page works standalone:
- Open
public/simulate.htmlin any browser - Click the preset buttons to test each action type:
- ๐งญ Navigate โ Simulates browser redirect (suppressed for safety)
โ ๏ธ Alert โ Triggers a browser alert via the protocol- ๐ Console โ Logs to browser DevTools console
- ๐ Multiple โ Fires two actions from one response
- ๐งฎ Calculator โ Full DOM manipulation demo (AI "calculates" and updates the page)
- Use the Custom Simulation textarea to test your own payloads
class AddToCart extends ClientActionTool
{
public function actionName(): string
{
return 'add_to_cart';
}
public function description(): Stringable|string
{
return 'Add a product to the shopping cart in the browser.';
}
public function schema(JsonSchema $schema): array
{
return $schema->object([
'product_id' => $schema->string('The product ID.'),
'quantity' => $schema->integer('Number of items to add.'),
])->require(['product_id', 'quantity']);
}
public function handle(Request $request): Stringable|string
{
return $this->dispatch($this->actionName(), [
'product_id' => $request->input('product_id'),
'quantity' => $request->input('quantity'),
]);
}
}const agent = new AIWebAgent();
agent.registerTool('add_to_cart', (payload) => {
fetch('/api/cart', {
method: 'POST',
body: JSON.stringify({
product_id: payload.product_id,
quantity: payload.quantity,
}),
}).then(() => {
updateCartBadge();
showToast('Item added to cart!');
});
});- Streaming support โ Parse action tokens from SSE (Server-Sent Events) streams in real-time
- Action acknowledgment โ Browser reports back to the server whether an action succeeded or failed
- Action queueing โ Buffer multiple rapid actions and execute sequentially with optional delays
- Conditional actions โ Server sends actions that only execute if certain DOM conditions are met
- Form auto-fill โ AI fills forms by targeting input fields by name/ID
- Click simulation โ AI triggers click events on buttons and links
- Scroll to element โ AI scrolls the viewport to a specific section
- CSS class toggling โ AI adds/removes classes (e.g., dark mode, highlights)
- Toast/notification system โ Non-blocking UI notifications instead of
alert() - Modal dialogs โ AI opens rich modal content with HTML
- Multi-step workflows โ AI chains multiple browser actions into sequences (e.g., "fill form โ submit โ navigate to confirmation")
- Visual feedback โ Highlight elements the AI is about to interact with
- Undo system โ Let users revert AI-triggered browser actions
- Permission system โ User approves certain actions before execution (e.g., "AI wants to navigate away, allow?")
- Sandbox mode โ Preview what actions the AI would take without executing them
- NPM package โ Publish the JS SDK as an installable package
- Composer package โ Publish the Laravel tools as a standalone package
- React/Vue adapters โ Framework-specific wrappers for the SDK
- WordPress plugin โ Bring AI browser actions to WordPress sites
- TypeScript types โ Full type definitions for the SDK
- Action marketplace โ Community-contributed tool packs (e-commerce, forms, analytics)
| Measure | Implementation |
|---|---|
| Whitelist-only execution | Only registered tools can run โ no eval() ever |
| URL validation | Navigation restricted to relative or whitelisted domains |
| Payload validation | Both backend schema validation and frontend type checking |
| No server-side effects | Client tools return tokens only โ they don't modify server state |
| HTML comment hiding | Tokens are invisible in rendered HTML, preventing social engineering |
| Layer | Technology | Purpose |
|---|---|---|
| AI Brain | Laravel 12+ with Laravel AI SDK | Tool definitions, LLM orchestration |
| Protocol | Hidden HTML comments with JSON | Communication bridge |
| Browser SDK | Vanilla JavaScript (AIWebAgent) |
Token parsing, tool execution |
| Test Page | Pure HTML/CSS/JS | No build tools needed |
Traditional AI chatbots are read-only โ they can only respond with text. This framework makes AI read-write on the web, enabling:
- E-commerce: "Add that jacket to my cart" โ AI actually adds it
- SaaS dashboards: "Show me last month's revenue" โ AI navigates to the report
- Customer support: "Reset my password" โ AI triggers the reset flow in the browser
- Accessibility: Voice-driven AI that physically operates the interface for users
The web browser becomes the AI's hands. ๐๏ธ
Built as a proof of concept โ proving that AI-driven browser actions are possible, practical, and ready for production.