CSS Sucks. You like layered CSS? You like DOM’s? You like S&M? Weirdo. I’ll bet you like accounting, too…
Well this simple tool will help the ones who are not odd. This tool, is for the rest of us…
What it is?
Here’s a minimal Python tool using PyAutoGUI, pynput, and pygetwindow that listens for the mouse to hover over new HTML containers (like in your ChatGPT DOM), and then dumps the currently hovered element’s HTML/text to a .txt
file. It uses OCR via Tesseract to read visible text and to extract DOM HTML if available.
Features:
- Detects mouse hover (with or without click).
- Uses OCR to dump visible hover container text.
- Logs timestamped
.txt
dumps on each capture
How do?
Press
'p'
to capture current mouse-hovered region.Saves one
.txt
file per keypress (instead of auto-interval).Captures OCR text from what’s visibly under the cursor.
Dumps into
hover_dumps/hover_YYYYMMDD_HHMMSS.txt
.
Step 1: Download and Install Tesseract
- Official Tesseract for Windows:
Home · UB-Mannheim/tesseract Wiki · GitHub
(Scroll down and choose thetesseract-ocr-w64-setup-...exe
installer)
Recommended version:
tesseract-ocr-w64-setup-5.3.1.20230401.exe
(stable, with English language files)
- Run the installer.
- During install, make sure this box is
checked:
“Add Tesseract to the system path for current user”
2. Install Python 3.11
If you’re anything like me, you have a bunch of different version of Python installed. So we needed to pick one which was guaranteed to work. Enter the need for Python 3.11..
Download: Python Release Python 3.11.0 | Python.org
Check it’s installed:
python --version
3. Install Dependencies
py -3.11 -m pip install pyautogui pynput pytesseract pillow opencv-python selenium
4. Run Scripts
this first, each time, changes depending upon path or the location of Brave or the window of subject, e.g.:
"C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" --remote-debugging-port=9222 --user-data-dir="C:\Temp\BraveProfile"
then this:
py -3.11 featsofstrength.py
featsofstrength.py
import time
import os
import threading
import pyautogui
import pygetwindow as gw
from pynput import keyboard
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# === Selenium attach to Brave ===
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222")
chrome_options.binary_location = r"C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe" # Adjust if needed
driver = webdriver.Chrome(options=chrome_options)
output_dir = "hover_dumps"
os.makedirs(output_dir, exist_ok=True)
def get_browser_window_coords(title_contains="Brave"):
for w in gw.getWindowsWithTitle(title_contains):
if w.visible and not w.isMinimized:
return (w.left, w.top)
return None
def get_device_pixel_ratio():
try:
return driver.execute_script("return window.devicePixelRatio") or 1.0
except:
return 1.0
def get_viewport_offset():
# Returns distance between outer window and inner viewport (browser chrome)
return driver.execute_script("""
return {
offsetX: window.screenX - window.screenLeft,
offsetY: window.screenY - window.screenTop
};
""")
def capture_dom_hover():
try:
screen_x, screen_y = pyautogui.position()
win_coords = get_browser_window_coords("Brave")
if not win_coords:
print("[!] Brave browser window not found or not focused.")
return
win_left, win_top = win_coords
pixel_ratio = get_device_pixel_ratio()
offset = get_viewport_offset()
# Convert screen to browser-relative coordinates (scaled)
browser_x = (screen_x - win_left - offset['offsetX']) / pixel_ratio
browser_y = (screen_y - win_top - offset['offsetY']) / pixel_ratio
script = f"""
(function() {{
const elem = document.elementFromPoint({browser_x:.2f}, {browser_y:.2f});
if (!elem) return null;
return {{
tag: elem.tagName,
text: elem.textContent,
html: elem.outerHTML
}};
}})()
"""
result = driver.execute_script(script)
if result:
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = os.path.join(output_dir, f"hover_{timestamp}.txt")
with open(filename, "w", encoding="utf-8") as f:
f.write(f"[Tag] {result['tag']}\n\n")
f.write("[TextContent]\n")
f.write((result['text'] or "").strip() + "\n\n")
f.write("[OuterHTML]\n")
f.write((result['html'] or "").strip() + "\n")
print(f"[+] Saved DOM hover to {filename}")
else:
print("[!] No DOM element found under cursor.")
except Exception as e:
print(f"[!] Error: {e}")
def on_press(key):
try:
if key.char == 'p':
print("[*] Capturing DOM element under cursor...")
threading.Thread(target=capture_dom_hover).start()
except AttributeError:
pass # ignore non-character keys
def main():
print("🖱️ Hover over a Brave browser element and press 'p' to capture it. Ctrl+C to quit.")
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
if __name__ == "__main__":
main()
Key Fixes & Upgrades:
- Dynamically computes the window offset using:
pyautogui
for screen coordinatespygetwindow
for browser window positiondriver.execute_script()
to get the inner (viewport) position of the browser tabwindow.devicePixelRatio
to scale correctly on high-DPI monitors
- Converts screen coords → accurate browser-relative
elementFromPoint
inputs.