From 3838aa17afd8c30164df144dd22fe56946167981 Mon Sep 17 00:00:00 2001 From: Benedikt Willi Date: Sat, 10 Jan 2026 00:19:21 +0100 Subject: [PATCH] Add DOM Visualization Feature with Integrated Browser Support - Introduced a new feature to visualize the Document Object Model (DOM) tree of the loaded web page. - Implemented keyboard shortcut (Ctrl+Shift+D) for generating and displaying the DOM graph. - Added core implementation files: - src/debug/dom_graph.py: Handles generation and rendering of graphs in DOT and SVG formats. - Created templates and documentation for the new feature, including: - docs/DOM_VISUALIZATION.md: Overview and usage instructions. - docs/DOM_GRAPH_UX.md: User experience design documentation. - Allowed the visualization to open in a new browser tab instead of an external viewer. - Enhanced visual representation through color coding of different HTML elements. - Implemented comprehensive tests for graph generation and page rendering. - Updated README.md to include usage instructions for DOM visualization. - Included test_holder.html as an example test page. - Modified various components in the browser to integrate tab management and enhance the graphical rendering experience. --- .gitignore | 9 + FEATURE_DOM_GRAPH.md | 146 ++++++++++ QUICKSTART_DOM_GRAPH.md | 80 ++++++ README.md | 10 + UPDATE_DOM_TAB.md | 152 ++++++++++ assets/pages/dom_graph.html | 232 ++++++++++++++++ docs/DOM_GRAPH_UX.md | 157 +++++++++++ docs/DOM_VISUALIZATION.md | 97 +++++++ src/browser/browser.py | 25 +- src/browser/chrome.py | 524 ++++++++++++++++++++++------------- src/browser/tab.py | 13 + src/debug/__init__.py | 1 + src/debug/dom_graph.py | 189 +++++++++++++ src/parser/html.py | 119 ++++++-- src/templates.py | 45 +++ test_dom.html | 35 +++ tests/test_dom_graph.py | 142 ++++++++++ tests/test_dom_graph_page.py | 67 +++++ tests/test_html_parsing.py | 56 ++-- 19 files changed, 1841 insertions(+), 258 deletions(-) create mode 100644 FEATURE_DOM_GRAPH.md create mode 100644 QUICKSTART_DOM_GRAPH.md create mode 100644 UPDATE_DOM_TAB.md create mode 100644 assets/pages/dom_graph.html create mode 100644 docs/DOM_GRAPH_UX.md create mode 100644 docs/DOM_VISUALIZATION.md create mode 100644 src/debug/__init__.py create mode 100644 src/debug/dom_graph.py create mode 100644 test_dom.html create mode 100644 tests/test_dom_graph.py create mode 100644 tests/test_dom_graph_page.py diff --git a/.gitignore b/.gitignore index c18dd8d..61ae5a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,10 @@ __pycache__/ +**/__pycache__/* +src/browser/__pycache__/* + +# DOM graph outputs +*.dot +*.svg + +# Test outputs +example_dom_graph.* diff --git a/FEATURE_DOM_GRAPH.md b/FEATURE_DOM_GRAPH.md new file mode 100644 index 0000000..0a4a0e0 --- /dev/null +++ b/FEATURE_DOM_GRAPH.md @@ -0,0 +1,146 @@ +# DOM Visualization Feature - Implementation Summary + +## Overview +Added a keyboard shortcut (Ctrl+Shift+D) to generate and visualize the DOM tree of the current tab as a graph. + +## Files Created + +### Core Implementation +- **src/debug/__init__.py** - Debug utilities package +- **src/debug/dom_graph.py** - DOM graph generation and visualization + - `generate_dot_graph()` - Generates Graphviz DOT format + - `save_dom_graph()` - Saves DOT file + - `render_dom_graph_to_svg()` - Renders to SVG (requires graphviz) + - `print_dom_tree()` - Text tree representation + +### Tests +- **tests/test_dom_graph.py** - Comprehensive test suite (10 tests, all passing) + - Tests graph generation, coloring, escaping, truncation + - Tests tree printing with proper indentation + - Tests depth limiting and attribute handling + +### Documentation +- **docs/DOM_VISUALIZATION.md** - Feature documentation +- **test_dom.html** - Example test page +- Updated **README.md** with keyboard shortcuts section + +## Implementation Details + +### Browser Integration (src/browser/chrome.py) + +1. **Keyboard Shortcut Setup** + - Added `_setup_keyboard_shortcuts()` method + - Registers GTK EventControllerKey for key presses + - Listens for Ctrl+Shift+D combination + +2. **DOM Graph Handler** + - Added `_on_key_pressed()` callback + - Added `_show_dom_graph()` method that: + - Gets current tab's DOM document + - Generates graph in DOT format + - Attempts SVG rendering (if graphviz installed) + - Falls back to DOT file + - Prints tree to console + - Shows info dialog with result + +3. **UI Feedback** + - Added `_show_info_dialog()` for user notifications + - Opens generated SVG automatically with xdg-open + +### Graph Features + +**Color Coding:** +- Light green: ``, `` +- Light yellow: Headings (`

`-`

`) +- Light gray: Block elements (`
`, `

`, ``) +- Light cyan: Lists (`