gravity-core
v1.0.25
Published
Gravity - AI-powered CSS layout diagnostics for any IDE. Connect your browser to get real-time layout issue detection.
Maintainers
Readme
gravity-core
Gravity - AI-powered CSS layout diagnostics for any IDE.
Connect your browser to get real-time layout issue detection. Works with VSCode, Cursor, Kiro, Warp, and any IDE with MCP support.
🎯 What It Does
Ask your AI assistant: "Why is my modal not showing?"
Gravity will:
- Connect to your browser
- Inspect the actual DOM element
- Analyze its position, styles, and visibility
- Return specific issues and fixes
🚀 Quick Start (5 minutes)
1. Install Package
npm install gravity-core2. Setup Extension
npx gravity-core setup-extensionThis extracts the Chrome extension to ~/.gravity-extension.
3. Load Extension in Chrome
- Open Chrome and go to
chrome://extensions - Enable "Developer mode" (toggle in top right)
- Click "Load unpacked"
- Select the
~/.gravity-extensionfolder - ✅ Done!
4. Setup Native Host
npx gravity-core setup-native-hostThis:
- Auto-detects your Gravity extension ID
- Asks for confirmation before modifying registry
- Sets up native messaging for Chrome
- Optionally restarts Chrome
5. Test Connection
npx gravity-core test-connectionThis verifies:
- ✅ Registry key exists
- ✅ Manifest is valid
- ✅ Extension ID is configured
- ✅ Native host is executable
- ✅ WebSocket connection works
6. Configure Your IDE
Gravity works with any IDE that supports MCP (Model Context Protocol).
Quick configuration examples:
VSCode (.vscode/mcp.json):
{
"servers": {
"gravity": {
"type": "stdio",
"command": "npx",
"args": ["gravity-core"]
}
}
}Cursor (.cursor/mcp.json):
{
"mcpServers": {
"gravity": {
"command": "npx",
"args": ["gravity-core"]
}
}
}Zed (settings.json):
{
"context_servers": {
"gravity": {
"command": "npx",
"args": ["gravity-core"]
}
}
}Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"gravity": {
"command": "npx",
"args": ["gravity-core"]
}
}
}📖 For complete configuration instructions for all IDEs, including Cline, Continue.dev, and troubleshooting, see MCP_CONFIGURATION.md
7. Start Diagnosing
Ask your AI:
- "Diagnose the #modal element"
- "Why is the .button not showing?"
- "Check if the browser is connected"
📊 Example Output
{
"element": "#modal",
"found": true,
"issues": [
{
"type": "offscreen-right",
"severity": "high",
"message": "Element extends 50px beyond right edge of viewport",
"suggestion": "Add max-width: 100% or use overflow: hidden on parent"
}
],
"position": {
"left": 100,
"top": 50,
"width": 500,
"height": 300
},
"viewport": {
"width": 1920,
"height": 1080
}
}🔌 How It Works
Your IDE (VSCode, Cursor, Kiro, etc.)
↓
MCP Server (gravity-core)
↓
Native Messaging Host (Windows Registry)
↓
Chrome Extension (running native bridge)
↓
Browser Tab (DOM, CSS, Layout data)No manual setup needed! The extension automatically runs the native bridge when you connect to a tab.
📚 Detected Issues
- 🔴 Offscreen elements - Left, right, top, bottom
- 🔴 Hidden elements - display: none, visibility: hidden, opacity: 0
- 🟡 Z-index issues - Missing or low z-index
- 🟡 Dimension issues - Zero width/height
- 🟢 Overflow issues - overflow: hidden clipping content
- 🟢 Positioning issues - Uncentered modals
🎯 Common Workflows
Fix Offscreen Modal
- Terminal: Run
npx gravity-core setup-extensionandnpx gravity-core setup-native-host - Chrome: Load extension from
~/.gravity-extension - Browser: Open page with broken layout
- Extension: Click icon → "Connect to Tab" (🟢 Green)
- IDE: Ask AI: "Diagnose the .modal element"
- AI: Shows "Element extends 50px beyond right edge"
- You: Add
max-width: 100%to CSS - Browser: Refreshes automatically
- AI: Diagnose again → ✅ Fixed!
Debug Hidden Element
- Browser: Open page with hidden element
- Extension: Connect to tab
- IDE: Ask AI: "Why is the #button not showing?"
- AI: "The element has display: none"
- You: Change CSS to
display: block - AI: Diagnose again → ✅ Visible!
🔧 CLI Commands
Setup Extension
Extract the Chrome extension to your home directory:
npx gravity-core setup-extensionCreates ~/.gravity-extension/ ready to load in Chrome.
Setup Native Host
Configure native messaging for Chrome:
npx gravity-core setup-native-hostThis command:
- Auto-detects your Gravity extension ID
- Asks for confirmation before modifying registry
- Copies native host to
~/.gravity-host/ - Patches manifest with extension ID
- Writes Windows registry entry
- Optionally restarts Chrome
Test Connection
Verify everything is working:
npx gravity-core test-connectionChecks:
- Registry key exists
- Manifest file is valid
- Extension ID is configured
- Native host is executable
- WebSocket connection works
- Browser handshake succeeds
Start MCP Server
Run the MCP server (used by your IDE):
npx gravity-coreShow Help
npx gravity-core --help🔧 API Reference
Gravity
import { Gravity } from 'gravity-core';
const bridge = new Gravity(options);Methods
connectBrowser(port?: number): Promise<void>
Connect to browser.
await bridge.connectBrowser();disconnectBrowser(): Promise<void>
Disconnect from browser.
await bridge.disconnectBrowser();isConnected(): boolean
Check if connected.
if (bridge.isConnected()) {
console.log('Connected!');
}diagnoseLayout(selector: string): Promise<DiagnosticResult>
Diagnose layout issues.
const result = await bridge.diagnoseLayout('#modal');
console.log(result.issues);Events
bridge.on('connected', () => {
console.log('Connected to browser!');
});
bridge.on('disconnected', () => {
console.log('Disconnected from browser');
});
bridge.on('error', (error) => {
console.error('Error:', error);
});🐛 Troubleshooting
"Could not find Gravity extension"
Solution:
- Run
gravity setup-extension - Open Chrome and go to
chrome://extensions - Enable "Developer mode"
- Click "Load unpacked"
- Select
~/.gravity-extension - Run
gravity setup-native-host
"Registry key not found"
Solution:
- Run
gravity setup-native-hostagain - You may need to run as Administrator
- Check that Chrome is installed in the default location
"WebSocket connection failed"
Solution:
- Make sure the MCP server is running:
gravity - Check that port 9224 is not blocked by firewall
- Try a different port:
GRAVITY_PORT=9225 gravity
"Element not found"
Solution:
- Check selector is correct
- Make sure element exists in page
- Try simpler selector:
divinstead of#modal
"Chrome is running" warning
Solution:
- The setup will ask if you want to restart Chrome
- Restart Chrome manually if you prefer
- Changes take effect after restart
📖 Documentation
- Setup Guide - Complete setup instructions
- Architecture - How it works under the hood
🚀 Supported IDEs
- ✅ VSCode
- ✅ Cursor
- ✅ Kiro
- ✅ Warp
- ✅ Any IDE with MCP support
🔒 Security
- ✅ Extension only connects to localhost
- ✅ WebSocket server only accepts local connections
- ✅ No external API calls
- ✅ All data stays local
- ✅ No user data collection
- ✅ Registry changes require explicit user confirmation
- ✅ No silent installations or modifications
📝 License
MIT
🤝 Contributing
Contributions welcome! Please open an issue or PR on GitHub.
📞 Support
Ready to diagnose layouts in real-time?
npm install gravity-core
npx gravity-core setup-extension
npx gravity-core setup-native-host
npx gravity-core test-connectionThen configure your IDE and start debugging! 🎉
