open-web-inspector
Version:
The open source web element inspector - AI-controllable DOM inspection with live CSS editing, hover highlighting, and developer tools integration
426 lines (315 loc) ⢠12.5 kB
Markdown
# Open Web Inspector š¤
**The open source AI-controllable web element inspector!**
A revolutionary, lightweight, embeddable JavaScript library that enables DOM
element inspection with hover highlighting, detailed CSS/HTML analysis, and
**external API control**. Perfect for AI landing pages, chatbots, developer
tools, and any website that needs intelligent element inspection capabilities.
## Features
- šÆ **Hover Highlighting**: Red border appears around elements when hovering in
analyze mode
- š **Element Inspector**: Click any element to see its HTML structure and CSS
styles
- š± **Unified Code Panel**: Modern FAB-style interface with synchronized
HTML/CSS navigation
- šØ **Live CSS Editing**: Edit CSS properties in real-time with visual feedback
- šø **Element Screenshots**: Capture and copy element screenshots to clipboard
- š¤ **AI Snapshot**: Generate AI-friendly code analysis summaries
- š³ **Interactive Element Tree**: Navigate DOM hierarchy with clickable
synchronized CSS updates
- šļø **External API Control**: Revolutionary AI-controllable interface with
global JavaScript API
- āØļø **Keyboard Shortcuts**: Ctrl+Shift+E to toggle, Escape to disable
- š **URL Parameter Support**: Auto-enable via ?open-web-inspector=true
- š” **DOM Events**: Custom events for advanced integrations
- š **Zero Dependencies**: Pure vanilla JavaScript, dynamically loads helpers
when needed
- š¦ **CDN Ready**: Single file include, works instantly
## Quick Start
### Method 1: CDN Include (Recommended)
š **Automatically updated via GitHub Actions CI/CD pipeline!**
```html
<!-- ā
Production (minified, ~79KB) -->
<script src="https://unpkg.com/open-web-inspector@latest/dist/open-web-inspector.min.js"></script>
<!-- š§ Development (unminified, ~134KB) -->
<script src="https://unpkg.com/open-web-inspector@latest/dist/open-web-inspector.js"></script>
<!-- š Alternative CDN (jsDelivr) -->
<script src="https://cdn.jsdelivr.net/npm/open-web-inspector@latest/dist/open-web-inspector.min.js"></script>
<!-- š Specific version (recommended for production) -->
<script src="https://unpkg.com/open-web-inspector@1.0.1/dist/open-web-inspector.min.js"></script>
```
**šÆ Quick Enable:**
```html
<script>
// Auto-enable on page load
window.addEventListener("DOMContentLoaded", () => {
OpenWebInspector.enable();
});
</script>
```
**š¤ AI-Controllable:**
```html
<script>
// Perfect for AI landing pages!
OpenWebInspector.enable();
// AI can call this to select specific elements
OpenWebInspector.selectElement(".my-component");
</script>
```
### Method 2: Manual Integration
```html
<script src="open-web-inspector.js"></script>
<script>
// Access the OpenWebInspector instance
const selector = window.OpenWebInspector;
// You can also manually toggle analyze mode
// selector.toggleAnalyzeMode();
</script>
```
## š¤ AI-Controllable Inspector (Revolutionary Feature!)
**The world's first AI-controllable web element inspector!** Perfect for AI
landing pages, chatbots, and automated workflows.
### Global JavaScript API
```javascript
// Enable analyze mode (AI: "Let me inspect that for you")
OpenWebInspector.enable();
// Disable analyze mode (AI: "Analysis complete")
OpenWebInspector.disable();
// Toggle analyze mode
OpenWebInspector.toggle();
// Check if currently active
OpenWebInspector.isActive(); // returns true/false
// Auto-select specific element (AI: "Let me check that button's CSS")
OpenWebInspector.selectElement(".my-button");
// Get version info
OpenWebInspector.getVersion(); // returns "2.0.0"
```
### AI Landing Page Integration Example
```javascript
// Your AI assistant can write and execute this:
OpenWebInspector.enable();
// User clicks element they want to inspect
// AI can then read the CSS data and provide suggestions
setTimeout(() => OpenWebInspector.disable(), 10000);
```
### Multiple Control Methods
#### š **Global API** (Primary Method)
```javascript
OpenWebInspector.enable(); // Perfect for AI assistants
```
#### āØļø **Keyboard Shortcuts**
- `Ctrl+Shift+E` - Toggle analyze mode
- `Escape` - Disable analyze mode
#### š” **DOM Events** (Advanced)
```javascript
// For complex integrations
document.dispatchEvent(new CustomEvent("open-web-inspector-enable"));
document.dispatchEvent(new CustomEvent("open-web-inspector-disable"));
document.dispatchEvent(
new CustomEvent("open-web-inspector-select", {
detail: { selector: ".my-element" },
}),
);
```
#### š **URL Parameters**
```
https://yoursite.com?open-web-inspector=true // Auto-enable
https://yoursite.com?inspect=.my-button // Auto-select element
```
### Perfect for AI Assistants!
Your AI can now:
- Enable inspection mode on demand
- Guide users to specific elements
- Analyze CSS and provide suggestions
- Disable when analysis is complete
- Work seamlessly with any chat interface
## Usage
1. **Enable Analyze Mode**: Use API, keyboard shortcut, or URL parameter
2. **Hover Elements**: Move your mouse over any element to see red highlighting
3. **Inspect Element**: Click on any highlighted element to open the inspector
4. **Navigate Tree**: Click elements in the tree view to switch context with
synchronized CSS
5. **Edit CSS Live**: Modify properties in real-time and see changes immediately
6. **Take Screenshots**: Click "šø Capture" to capture and copy element image
7. **AI Analysis**: Click "⨠AI Snap" to copy AI-friendly code summary
8. **Close Inspector**: Click the X button, press Escape, or use the API
## Advanced Features
### šø Element Screenshots
- **One-click capture**: Automatically captures the selected element as a
high-quality PNG image
- **Clipboard integration**: Images are directly copied to your clipboard for
easy pasting
- **Smart cropping**: Only captures the specific element, not the entire page
- **Dynamic loading**: html2canvas library is loaded only when screenshot
feature is used
- **Visual feedback**: Button shows progress and completion status
### š¤ AI Snapshot
- **AI-optimized format**: Generates structured summaries perfect for pasting
into AI chats
- **Complete context**: Includes element path, HTML structure, CSS styles, and
computed values
- **Markdown formatted**: Clean, readable format with syntax highlighting
- **Development guidance**: Includes contextual notes to help AI understand the
analysis purpose
### š³ Interactive Element Tree
- **Clickable navigation**: Click any element in the tree to switch inspector
context
- **Visual hierarchy**: Clear indentation and icons show DOM structure
- **Real-time updates**: Tree updates when navigating to different elements
- **Smart highlighting**: Selected elements are highlighted on the actual page
## Inspector Features
### HTML Tab
- Complete HTML structure of the selected element
- Element path showing the CSS selector path
- Formatted, readable HTML output
### CSS Styles Tab
- Applied CSS styles from stylesheets and inline styles
- Property names and values clearly displayed
- Source indication (inline vs computed)
### Computed Styles Tab
- All computed CSS properties and their final values
- Comprehensive view of all styling applied to the element
## Keyboard Shortcuts
- `Ctrl+Shift+E` - Toggle analyze mode on/off
- `Escape` - Disable analyze mode and close inspector
## Browser Compatibility
- Chrome 60+
- Firefox 55+
- Safari 12+
- Edge 79+
## File Structure
```
open-web-inspector/
āāā open-web-inspector.js # Main library file
āāā index.html # Demo page
āāā README.md # This file
```
## Advanced Configuration
The library automatically initializes and provides a comprehensive external API:
```javascript
// š¤ AI-Friendly Global API
OpenWebInspector.enable(); // Enable analyze mode
OpenWebInspector.disable(); // Disable analyze mode
OpenWebInspector.toggle(); // Toggle analyze mode
OpenWebInspector.isActive(); // Check if active (returns boolean)
OpenWebInspector.selectElement(".btn"); // Auto-select element
OpenWebInspector.getVersion(); // Get version info
// š” DOM Events (Advanced Integrations)
document.dispatchEvent(new CustomEvent("open-web-inspector-enable"));
document.dispatchEvent(new CustomEvent("open-web-inspector-disable"));
document.dispatchEvent(
new CustomEvent("open-web-inspector-select", {
detail: { selector: ".my-element" },
}),
);
// š URL Parameters (Auto-Enable)
// ?open-web-inspector=true - Auto-enable on page load
// ?inspect=.my-button - Auto-select specific element
// āØļø Keyboard Events (Built-in)
// Ctrl+Shift+E - Toggle analyze mode
// Escape - Disable analyze mode
```
### Console Feedback
The library provides helpful console messages:
```
š OpenWebInspector Global API Ready!
š Available methods:
⢠OpenWebInspector.enable()
⢠OpenWebInspector.disable()
⢠OpenWebInspector.toggle()
⢠OpenWebInspector.isActive()
⢠OpenWebInspector.selectElement(selector)
⢠OpenWebInspector.getVersion()
āØļø Keyboard shortcuts active:
⢠Ctrl+Shift+E = Toggle analyze mode
⢠Escape = Disable analyze mode
š” DOM events listening:
⢠open-web-inspector-enable
⢠open-web-inspector-disable
⢠open-web-inspector-toggle
⢠open-web-inspector-select (with detail.selector)
š URL parameters supported:
⢠?open-web-inspector=true (auto-enable)
⢠?inspect=.selector (auto-select element)
```
## CSS Classes Used
The library uses CSS classes with the `open-web-inspector-` prefix to avoid
conflicts:
- `.open-web-inspector-highlight` - Applied to hovered elements
- `.open-web-inspector-popup` - Main popup container
- `.open-web-inspector-overlay` - Background overlay
- `.open-web-inspector-analyze-cursor` - Applied to body when in analyze mode
## Customization
You can override the default styles by adding your own CSS after including the
library:
```css
.open-web-inspector-highlight {
outline-color: blue !important; /* Change highlight color */
}
.open-web-inspector-popup {
max-width: 600px !important; /* Adjust popup size */
}
```
## š Deployment & CI/CD
This project features **fully automated deployment** via GitHub Actions!
### š¦ Automated NPM Publishing
Every release automatically:
- ā
Builds optimized production bundles
- ā
Publishes to npm registry
- ā
Updates CDN links (unpkg + jsDelivr)
- ā
Generates comprehensive release notes
- ā
Validates build integrity
### šÆ Release Process
**Option 1: GitHub Release (Recommended)**
```bash
# Create a new release on GitHub
# Actions automatically build & publish to npm + CDN
```
**Option 2: Manual Trigger**
```bash
# Use GitHub Actions workflow dispatch
# Go to Actions ā Release & Publish ā Run workflow
```
**Option 3: Local Development**
```bash
npm run version:patch # 1.0.0 ā 1.0.1
npm run version:minor # 1.0.1 ā 1.1.0
npm run version:major # 1.1.0 ā 2.0.0
git push origin main --tags
```
### š Build Pipeline
```yaml
Trigger ā Build ā Test ā Optimize ā Publish ā CDN Update
ā ā ā ā ā ā
GitHub Terser Smoke 79KB NPM Auto-Live
Action Build Test Bundle Publish on CDN!
```
### š CDN Availability
After each release, your package is **instantly available** on:
| CDN | URL Template | Update Time |
| ------------ | ------------------------------------------------------------ | ----------- |
| **unpkg** | `https://unpkg.com/open-web-inspector@{version}/` | ~1 minute |
| **jsDelivr** | `https://cdn.jsdelivr.net/npm/open-web-inspector@{version}/` | ~2 minutes |
### š§ Development Setup
```bash
# Clone and setup
git clone <your-repo>
cd open-web-inspector
npm install
# Start development
npm run dev # Start server on :8002
npm run build # Build both dev + production
npm run size # Check bundle sizes
# Test examples
open http://localhost:8002/examples/
```
## License
MIT License - feel free to use in any project!
## Contributing
1. Fork the repository
2. Create your feature branch
3. Make your changes
4. Test with the demo page
5. Submit a pull request
## Demo
Open `index.html` in your browser to see the library in action with a full demo
page showcasing various elements and styling scenarios.