Overview
The Editor class provides a code editor-like interface for viewing and modifying scripts and stylesheets in running web pages via Chrome DevTools Protocol. Key features:- List, read, search, and edit JavaScript and CSS files
- Changes are applied in-memory (persist until page reload)
- No server access needed - edits modify the running V8 instance
- Claude Code-like interface:
list(),read(),edit(),grep()
- Test quick fixes without rebuilding
- Toggle debug flags in production code
- Search page scripts for patterns
- Modify CSS for visual testing
Quick Start
Creating an Editor
Debugger.scriptParsed events.
Listing Scripts and Stylesheets
List All Resources
Filter by Pattern
inline://{id} URLs.
Reading Source Code
Read Full File
Read Specific Range
url- Script or stylesheet URL (inline scripts haveinline://{id}URLs)offset- Line number to start from (0-based, default 0)limit- Number of lines to return (default 2000)
Read CSS Files
Editing Code
Basic Edit
- Performs exact string replacement (like Claude Code’s Edit tool)
oldStringmust match exactly once in the file- If not found: throws error
- If found multiple times: throws error asking for more context
Edit CSS
Dry Run
Edit Inline Scripts
Inline scripts (scripts without a URL) getinline://{id} URLs:
Searching Code
Search All Files
Search Specific File Types
Search with Pattern Filters
Writing Complete Files
write() replaces entire file content. Prefer edit() for targeted changes.
Parameters:
url- Script or stylesheet URLcontent- New complete contentdryRun- Validate without applying (default false, JS only)
Complete Examples
Toggle Debug Mode
Search and Replace Console Logs
Edit Inline Script
CSS Color Scheme Switch
Implementation Details
How Edits Work
For JavaScript:- Uses
Debugger.setScriptSourceCDP command (Chrome versions below 142) - For Chrome 142+: Falls back to
Runtime.evaluateto re-execute modified script - Edits modify the running V8 instance
- Changes persist until page reload
- Works best for scripts that define functions at global scope
- Uses
CSS.setStyleSheetTextCDP command - Changes apply immediately to rendered page
- No page flash or reload
Limitations
- In-memory only - edits are not saved to disk or server
- Lost on reload - changes disappear when page reloads
- Scope dependent - JavaScript edits work best for global function definitions
- No source maps - edits apply to compiled/minified code, not original source
Chrome 142+ Compatibility
Chrome deprecatedDebugger.setScriptSource in version 142 (Feb 2026). The Editor automatically falls back to re-executing scripts via Runtime.evaluate, which works for most use cases.
Best Practices
Preferedit() over write():
grep() to find targets: