Skip to content

ythx-101/grok-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŒ‰ grok-bridge v3.0

Turn SuperGrok into a REST API + CLI tool. No API key needed.

How it works

Your Terminal/Script β†’ Safari JS injection β†’ grok.com β†’ Response extracted via DOM

Two modes:

REST API (recommended)

# Start the server on your Mac
python3 scripts/grok_bridge.py --port 19998

# Query from anywhere
curl -X POST http://your-mac:19998/chat \
  -H "Content-Type: application/json" \
  -d '{"prompt":"What is the mass of the sun?","timeout":60}'

# Health check
curl http://your-mac:19998/health

# Read current conversation
curl http://your-mac:19998/history

CLI (legacy)

# Local
bash scripts/grok_chat.sh "Explain quantum tunneling"

# Remote via SSH
MAC_SSH="ssh user@your-mac" bash scripts/grok_chat.sh "Write a haiku" --timeout 90

Requirements

  • macOS with Safari
  • Logged into grok.com (free or SuperGrok)
  • Safari > Settings > Advanced > Show features for web developers βœ“
  • Safari > Develop > Allow JavaScript from Apple Events βœ“
  • No Accessibility permission needed (v3 uses JS injection, not System Events)

API Endpoints

Method Path Description
POST /chat Send prompt, wait for response
POST /new Start new conversation
GET /health Health check (Safari URL, grok status)
GET /history Read current page conversation

Version History

v1 v2 v3
Input Peekaboo UI pbcopy + Cmd+V JS execCommand('insertText')
Submit UI click System Events Return JS button.click()
Permissions Peekaboo + Accessibility Accessibility None (pure JS injection)
Interface CLI only CLI only REST API + CLI
Dependencies Peekaboo (brew) None None (stdlib only)
Speed ~30s ~3s ~3s

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  HTTP Client β”‚  POST /chat         β”‚      macOS            β”‚
β”‚  (anywhere)  β”‚ ──────────────────→ β”‚                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚  grok_bridge.py       β”‚
                                     β”‚  ↓ osascript          β”‚
                                     β”‚  Safari do JavaScript β”‚
                                     β”‚  ↓ execCommand        β”‚
                                     β”‚  grok.com textarea    β”‚
                                     β”‚  ↓ button.click()     β”‚
                                     β”‚  Grok responds        β”‚
                                     β”‚  ↓ DOM poll           β”‚
                                     β”‚  Response extracted   β”‚
                                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Insight (v3)

React controlled inputs ignore JavaScript value setter, synthetic InputEvent, and even nativeInputValueSetter.

What doesn't work from SSH:

  • ❌ osascript keystroke β€” blocked by macOS Accessibility
  • ❌ CGEvent (Swift) β€” HID events don't reach web content
  • ❌ JS InputEvent / nativeInputValueSetter β€” React ignores synthetic events

What does work:

  • βœ… document.execCommand('insertText') β€” triggers real input in the browser
  • βœ… JS button.click() on Send button β€” no System Events needed

Zero permissions, zero dependencies, pure JavaScript injection via AppleScript.

Credits

v3 architecture designed by Claude Opus 4.6 (via Antigravity), System Events bypass by 小灡 🦞.

License

MIT

About

πŸŒ‰ Turn SuperGrok into a REST API β€” Safari browser automation bridge for AI agents

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors