A Chrome browser extension that inspects DOM elements for hardcoded CSS values and highlights them with a red border. This tool helps developers identify elements that are not using design tokens for consistent styling.
- Real-time Inspection: Scans all DOM elements for hardcoded CSS values
- Visual Highlighting: Elements with hardcoded values are highlighted with a red border and warning label
- Smart Detection: Only highlights developer-applied styles, ignoring user agent (browser default) styles
- Browser-Agnostic: Works across all browsers without relying on hardcoded browser defaults
- Comprehensive Detection: Detects hardcoded values for:
- Spacing (margin, padding, width, height, etc.)
- Colors (hex, rgb, rgba, hsl, hsla)
- Font sizes
- Border radius
- Z-index values
- Opacity values
- Design Token Recognition: Automatically recognizes CSS custom properties (
var(--token-name)
) - User Agent Style Filtering: Intelligently filters out browser default styles
- Live Updates: Monitors DOM changes and inspects new elements automatically
- Statistics: Shows count of hardcoded values found and elements inspected
- Clone or download this repository
- Open Chrome and navigate to
chrome://extensions/
- Enable "Developer mode" in the top right corner
- Click "Load unpacked" and select the extension directory
- The extension should now appear in your extensions list
- Open Chrome and navigate to
chrome://extensions/
- Enable "Developer mode"
- Click "Load unpacked" and select this directory
- The extension will be installed and ready to use
This project includes a complete automation pipeline for publishing to the Chrome Web Store.
-
Setup Chrome Web Store API:
npm run setup-chrome-store
-
Configure GitHub Secrets (see PUBLISHING.md for details):
EXTENSION_ID
: Your Chrome extension IDCLIENT_ID
: OAuth 2.0 Client IDCLIENT_SECRET
: OAuth 2.0 Client SecretREFRESH_TOKEN
: OAuth 2.0 Refresh Token
-
Publish Automatically:
# Create a new version tag git tag v1.0.1 git push origin v1.0.1
# Build and validate extension
npm run build
# Create package for Chrome Web Store
npm run package
# Setup Chrome Web Store API (interactive guide)
npm run setup-chrome-store
# Lint and format code
npm run lint
npm run format
- Automatic: Push a version tag (e.g.,
v1.0.1
) to trigger automated publishing - Manual: Use GitHub Actions workflow dispatch to publish specific versions
- Local: Run
npm run package
and manually upload the generated zip file
For detailed instructions, see PUBLISHING.md.
- Activate the Extension: Click the extension icon in your Chrome toolbar
- Start Inspection: Click "Start Inspection" in the popup
- View Results: Elements with hardcoded CSS values will be highlighted with:
- Red border outline
- Warning label ("
β οΈ Hardcoded CSS") - Pulsing animation
- Tooltip on hover
- Stop Inspection: Click "Stop Inspection" to clear highlights and stop monitoring
margin: 16px
padding: 8px
font-size: 14px
color: #333333
background-color: rgb(255, 255, 255)
border-radius: 4px
width: 200px
height: 100px
z-index: 1000
opacity: 0.8
margin: var(--spacing-md)
color: var(--color-primary)
font-size: var(--font-size-body)
background-color: var(--color-background)
- Browser default button styles
- Default form element styles
- Default heading styles
- Default paragraph and list styles
- Any other browser-provided default styles
The extension uses multiple browser-agnostic methods to distinguish between developer-applied styles and user agent styles:
- Inline Style Detection: Identifies explicitly set inline styles as developer-applied
- Stylesheet Source Analysis: Identifies styles coming from user agent stylesheets vs developer stylesheets
- Baseline Comparison: Creates baseline elements to compare against user agent defaults dynamically
- Inheritance Tracking: Follows style inheritance to determine the original source
- CSS Cascade Analysis: Analyzes CSS specificity and cascade to determine style sources
- Dynamic User Agent Detection: Uses runtime analysis instead of hardcoded browser defaults
The extension can be customized by modifying the following files:
content.js
: Main inspection logic and detection patternscontent.css
: Visual styling for highlighted elementspopup.html
&popup.js
: Extension popup interface
The extension uses regex patterns to detect:
- Spacing Values: Any numeric value with units (px, rem, em, etc.)
- Color Values: Hex colors, rgb/rgba, hsl/hsla, named colors
- Font Sizes: Numeric values with units for font properties
- Border Radius: Numeric values with units for border-radius
- Z-index: Numeric values for z-index property
- Opacity: Numeric values for opacity property
The following values are considered acceptable and won't trigger highlighting:
0
,0px
(zero values)auto
(automatic values)none
(no value)- CSS custom properties using
var(--token-name)
- User agent (browser default) styles
- Inherited styles from user agent defaults
- Chrome (recommended)
- Chromium-based browsers (Edge, Brave, etc.)
- Firefox (with modifications to manifest.json)
- Safari (with modifications to manifest.json)
mds-style-inspector/
βββ manifest.json # Extension manifest
βββ popup.html # Extension popup interface
βββ popup.js # Popup logic
βββ content.js # Main inspection script
βββ content.css # Highlight styles
βββ test-user-agent.html # Test file for user agent detection
βββ icons/ # Extension icons
βββ README.md # This file
-
StyleInspector Class (
content.js
):- Main inspection logic
- Pattern matching for hardcoded values
- Browser-agnostic user agent style detection
- DOM monitoring and highlighting
-
Popup Interface (
popup.html/js
):- Start/stop controls
- Statistics display
- Status indicators
-
Visual Feedback (
content.css
):- Red border highlighting
- Warning labels
- Pulsing animation
- Tooltips
-
Smart Detection Methods:
isDeveloperAppliedStyle()
: Determines if a style is developer-appliedisStyleFromUserAgent()
: Detects user agent styles dynamicallyisBaselineStyle()
: Compares against user agent defaultsisCascadeDeveloperStyle()
: Analyzes CSS cascade and specificitygetCSSRulesForElement()
: Analyzes stylesheet sources
Use test-user-agent.html
to test the browser-agnostic user agent detection:
- Load the test file in Chrome
- Activate the extension
- Start inspection
- Verify that:
- Elements with user agent styles are NOT highlighted
- Elements with developer-applied styles ARE highlighted
- Elements with design tokens are NOT highlighted
- Mixed elements show appropriate highlighting
- Check that the extension is enabled in
chrome://extensions/
- Refresh the page you're inspecting
- Check the browser console for any error messages
- Ensure the page has elements with developer-applied hardcoded CSS values
- Check that the inspection is active (green status in popup)
- Try refreshing the page and restarting inspection
- Verify that elements have actual developer styles, not just user agent defaults
- The extension now filters out user agent styles automatically using browser-agnostic methods
- If you're still seeing too many highlights, check the console for detection logs
- The extension logs which styles are being filtered and why
- The extension inspects all DOM elements, which can be resource-intensive on large pages
- Consider stopping inspection when not needed
- The extension automatically monitors DOM changes, so it will inspect new elements as they're added
- Fork the repository
- Make your changes
- Test thoroughly using the provided test files
- Submit a pull request
This project is open source and available under the MIT License.
For issues, questions, or feature requests, please open an issue on the GitHub repository.