@sashbot/uibridge
v1.6.0
Published
π€ AI-friendly live session automation with REAL screenshot backgrounds (no transparency issues!) - control your EXISTING browser with visual debug panel. Perfect for AI agents!
Maintainers
Keywords
Readme
π UIBridge - AI-Powered Browser Automation for AI Agents
Primary Method: Use PowerShell helper functions for reliable, tested browser automation with built-in error handling and JSON validation.
π― What UIBridge Does
UIBridge provides reliable browser automation specifically designed for AI agents. It runs automation against a real browser with visual feedback and comprehensive error handling.
Perfect for: AI agents, automation testing, web scraping, form filling, UI testing.
π Quick Start for AI Agents (Recommended Method)
Step 1: Install UIBridge
npm install @sashbot/uibridgeStep 2: Start the Server
# Start the UIBridge server (keep this running)
node node_modules/@sashbot/uibridge/api-server.cjsβ
Server Status: You should see UIBridge API Server running on http://localhost:3002
Step 3: Load PowerShell Helper Functions
# Download the helper functions (includes JSON corruption fixes)
curl -o uibridge-powershell-helpers.ps1 https://unpkg.com/@sashbot/uibridge@latest/uibridge-powershell-helpers.ps1
# Load the functions (do this first in every session)
. .\uibridge-powershell-helpers.ps1Step 4: Verify Everything Works
# Test server connection
Test-UIBridgeServer
# Start a complete automation session (opens browser and takes screenshot)
Start-UIBridgeSession -Url "https://example.com"π That's it! You now have reliable browser automation with proper error handling.
π€ Core AI Agent Commands (Primary Method)
π Connection & Navigation
# Always load helpers first in every session
. .\uibridge-powershell-helpers.ps1
# Test server connection
Test-UIBridgeServer
# Navigate to any URL
Open-UIBridgePage -Url "https://example.com"
Open-UIBridgePage -Url "http://localhost:3000"
# Get current page information
Get-UIBridgePageInfoπ±οΈ Clicking Elements (Robust with Multiple Strategies)
# Click by text content (RECOMMENDED - most reliable)
Click-UIBridgeText -Text "Submit"
Click-UIBridgeText -Text "Login"
Click-UIBridgeText -Text "Save Changes"
# Click by test ID (best for testing)
Click-UIBridgeTestId -TestId "submit-btn"
Click-UIBridgeTestId -TestId "login-button"
# Click by CSS selector (when other methods don't work)
Click-UIBridgeElement -Selector "#save-button"
Click-UIBridgeElement -Selector ".submit-btn"
Click-UIBridgeElement -Selector "button[type='submit']"πΈ Screenshots (Auto-Saved with Validation)
# Basic screenshot (recommended)
Take-UIBridgeScreenshot
# Full page screenshot with options
Take-UIBridgeScreenshot -FullPage $true -Format "png" -Quality 90
# Screenshot with specific background color
Take-UIBridgeScreenshot -BackgroundColor "white"
Take-UIBridgeScreenshot -BackgroundColor "transparent"
Take-UIBridgeScreenshot -BackgroundColor "auto" # Auto-detect page background
# List all saved screenshots
Get-UIBridgeScreenshotsπ Complete Automation Workflows
# Complete automation session with error handling
Start-UIBridgeSession -Url "https://example.com"
# Example: Form automation workflow
. .\uibridge-powershell-helpers.ps1
Test-UIBridgeServer
Open-UIBridgePage -Url "https://example.com/form"
Take-UIBridgeScreenshot # Before
Click-UIBridgeText -Text "Fill Form"
Take-UIBridgeScreenshot # After
Click-UIBridgeTestId -TestId "submit-btn"
Take-UIBridgeScreenshot # Final result
Get-UIBridgeScreenshots # Review all screenshotsβ Why PowerShell Helpers Are the Primary Method
π‘οΈ Built-in Reliability (v1.2.5+ includes JSON corruption fixes)
- JSON Validation: Every command validates JSON before sending to prevent corruption errors
- Consistent Formatting: All JSON uses proper depth and escaping
- Error Handling: Clear error messages with troubleshooting guidance
- Special Character Support: Handles quotes, apostrophes, unicode, emoji correctly
π― AI Agent Optimized
- Simple Function Calls:
Click-UIBridgeText -Text "Submit"instead of complex JSON - Multiple Click Strategies: Automatic fallback between text, testId, and CSS selectors
- Auto-Save Screenshots: Timestamps and organized file management
- Connection Testing: Built-in server health checks
π§ͺ Comprehensive Testing
- 17 Unit Tests: JSON generation, special characters, error handling
- Integration Tests: Real server and browser testing
- Regression Prevention: Prevents the return of JSON corruption bugs
# Run tests to verify everything works
pwsh -ExecutionPolicy Bypass -File test-powershell-helpers.ps1π§ When to Use Alternative Methods
The PowerShell helpers are the recommended primary method, but use alternatives for these specific scenarios:
π Live Session Method (Visual Debugging)
Use when: You need to see automation happen in real-time in your own browser
<!-- Add to your web app for live visual feedback -->
<script src="http://localhost:3002/uibridge-client.js"></script># Download live session helpers
curl -o uibridge-live-session-helpers.ps1 https://unpkg.com/@sashbot/uibridge@latest/uibridge-live-session-helpers.ps1
. .\uibridge-live-session-helpers.ps1
# Control YOUR browser live
Click-UIBridgeLiveText -Text "Submit" # You see it happen in your browser!π§ Direct HTTP API
Use when:
- Working from non-PowerShell environments (Python, Node.js, etc.)
- Need custom JSON structures not supported by helpers
- Building your own wrapper functions
# Direct HTTP for other languages
curl -X POST http://localhost:3002/execute \
-H "Content-Type: application/json" \
-d '{"command":"click","selector":{"text":"Submit"}}'π¦ NPM Package Integration
Use when: Building JavaScript/TypeScript applications with UIBridge
import { UIBridge } from '@sashbot/uibridge';
const bridge = new UIBridge();
await bridge.click({ text: 'Submit' });π¨ Troubleshooting & Error Resolution
Problem: JSON corruption errors
β FIXED in v1.2.5+ The PowerShell helpers now generate valid JSON consistently:
# Verify the fix works
pwsh -ExecutionPolicy Bypass -File test-powershell-helpers.ps1
# Should show: All tests passed! β
Problem: Server not accessible
Test-UIBridgeServer
# If this fails:
# 1. Restart server: node node_modules/@sashbot/uibridge/api-server.cjs
# 2. Check firewall/antivirus blocking port 3002
# 3. Try different port: . .\uibridge-powershell-helpers.ps1 -ServerUrl "http://localhost:3003"Problem: Elements not found
# Try multiple strategies in order:
Click-UIBridgeText -Text "Button Text" # Try this first (most reliable)
Click-UIBridgeTestId -TestId "button-id" # If text doesn't work
Click-UIBridgeElement -Selector "#button-id" # If test ID doesn't work
# Take screenshot to see current page state
Take-UIBridgeScreenshotProblem: Special characters in text
# These all work correctly with the fixed helpers:
Click-UIBridgeText -Text "Text with ""quotes"" and 'apostrophes'"
Click-UIBridgeText -Text "Button with emoji π"
Click-UIBridgeText -Text "Unicode: ζ΅θ― Ψ§ΩΨΉΨ±Ψ¨ΩΨ© ΡΡΡΡΠΊΠΈΠΉ"π― AI Agent Best Practices
β DO (Primary Method):
# 1. Always load helpers first
. .\uibridge-powershell-helpers.ps1
# 2. Test connection before automating
Test-UIBridgeServer
# 3. Use text-based clicking first (most reliable)
Click-UIBridgeText -Text "Submit"
# 4. Take screenshots to verify actions
Take-UIBridgeScreenshot
# 5. Use complete workflows
Start-UIBridgeSession -Url "https://example.com"β οΈ AVOID:
- Don't construct JSON manually - use the helper functions
- Don't skip
Test-UIBridgeServer- always verify connection - Don't use complex CSS selectors if text clicking works
- Don't forget to handle errors with try/catch blocks
π Helper Functions Reference
Core Functions
| Function | Purpose | Example |
|----------|---------|---------|
| Test-UIBridgeServer | Check server connection | Test-UIBridgeServer |
| Open-UIBridgePage | Navigate to URL | Open-UIBridgePage -Url "https://example.com" |
| Take-UIBridgeScreenshot | Capture page screenshot | Take-UIBridgeScreenshot -FullPage $true |
| Click-UIBridgeText | Click by text content | Click-UIBridgeText -Text "Submit" |
| Click-UIBridgeTestId | Click by test ID | Click-UIBridgeTestId -TestId "submit-btn" |
| Click-UIBridgeElement | Click by CSS selector | Click-UIBridgeElement -Selector "#btn" |
| Get-UIBridgePageInfo | Get page title/URL | Get-UIBridgePageInfo |
| Get-UIBridgeScreenshots | List saved screenshots | Get-UIBridgeScreenshots |
| Start-UIBridgeSession | Complete automation setup | Start-UIBridgeSession -Url "https://example.com" |
Advanced Usage
# Custom timeout for slow pages
Click-UIBridgeText -Text "Submit" -Timeout 10000
# High quality screenshot
Take-UIBridgeScreenshot -Quality 95 -Format "png"
# Multiple screenshots for comparison
Take-UIBridgeScreenshot # Before action
Click-UIBridgeText -Text "Change Background"
Take-UIBridgeScreenshot # After action㪠Testing & Validation
Run Built-in Tests
# Test JSON generation and helper functions
pwsh -ExecutionPolicy Bypass -File test-powershell-helpers.ps1
# Expected result:
# π Test Results Summary
# Total Tests: 17
# Passed: 17 β
# Failed: 0 β
Integration with CI/CD
# In your build scripts
$testResult = & pwsh -ExecutionPolicy Bypass -File test-powershell-helpers.ps1
if ($LASTEXITCODE -ne 0) {
throw "UIBridge PowerShell helper tests failed"
}π Why UIBridge PowerShell Helpers Are Perfect for AI Agents
- π‘οΈ Reliability: Built-in JSON validation prevents corruption errors
- π― Simplicity:
Click-UIBridgeText -Text "Submit"instead of complex APIs - πΈ Auto-Management: Screenshots auto-save with timestamps
- π Error Handling: Clear error messages with troubleshooting guidance
- π€ AI-Optimized: Functions designed specifically for AI agent workflows
- β‘ Fast Setup: Load helpers, test connection, start automating
- π§ͺ Tested: 17 unit tests ensure reliability
- π Universal: Works with any web application
π Additional Resources
- π§ Advanced Configuration
- π€ AI Agent Guidelines
- π¦ NPM Package
- π GitHub Issues
π Built for AI Agents: UIBridge provides the most reliable browser automation for AI agents with comprehensive error handling, JSON validation, and intuitive PowerShell functions.
