headless-engine 1.0.2

A high-performance, lightweight (<30MB RAM) headless browser engine written in Rust for AI agents, web automation, and LLM data ingestion.
Documentation
import subprocess
import json
import time
import psutil
import os
import shutil

def profile_engine():
    bin_path = os.path.expandvars(r"%LOCALAPPDATA%\Programs\headless-engine\headless-engine.exe")
    if not os.path.exists(bin_path):
        bin_path = "target/release/headless-engine.exe"
    
    print(f"=== Headless Engine Memory Footprint Audit ===")
    print(f"Binary Target: {bin_path}\n")
    
    # 1. Idle Process
    proc = subprocess.Popen([bin_path, "--stdio"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    p = psutil.Process(proc.pid)
    time.sleep(0.5)
    
    idle_mem_mb = p.memory_info().rss / (1024 * 1024)
    print(f"1. Idle Process (JSON-RPC Engine Initialized):    {idle_mem_mb:.2f} MB")
    
    # 2. Live Page Navigation + DOM Parsing
    nav_cmd = {"jsonrpc": "2.0", "id": 1, "method": "tab.navigate", "params": {"url": "https://news.ycombinator.com"}}
    proc.stdin.write(json.dumps(nav_cmd) + "\n")
    proc.stdin.flush()
    resp1 = proc.stdout.readline()
    
    # Extract Markdown
    md_cmd = {"jsonrpc": "2.0", "id": 2, "method": "tab.extractMarkdown"}
    proc.stdin.write(json.dumps(md_cmd) + "\n")
    proc.stdin.flush()
    resp2 = proc.stdout.readline()
    
    time.sleep(0.3)
    active_mem_mb = p.memory_info().rss / (1024 * 1024)
    print(f"2. Active SERP/Page (Hacker News Loaded + AST):  {active_mem_mb:.2f} MB")
    
    # 3. Heavy Target: Wikipedia AI
    nav_cmd2 = {"jsonrpc": "2.0", "id": 3, "method": "tab.navigate", "params": {"url": "https://en.wikipedia.org/wiki/Artificial_intelligence"}}
    proc.stdin.write(json.dumps(nav_cmd2) + "\n")
    proc.stdin.flush()
    resp3 = proc.stdout.readline()
    
    time.sleep(0.3)
    heavy_mem_mb = p.memory_info().rss / (1024 * 1024)
    print(f"3. Large Target (Wikipedia AI 550KB DOM):         {heavy_mem_mb:.2f} MB")
    
    # 4. Multi-Tab Concurrency Test (5 Isolated Tabs)
    tab_ids = []
    for i in range(5):
        tab_cmd = {"jsonrpc": "2.0", "id": 10 + i, "method": "engine.createTab", "params": {"profile": "ChromeWindows"}}
        proc.stdin.write(json.dumps(tab_cmd) + "\n")
        proc.stdin.flush()
        line = proc.stdout.readline()
        data = json.loads(line)
        tab_ids.append(data.get("result", {}).get("tab_id"))
    
    multi_mem_mb = p.memory_info().rss / (1024 * 1024)
    print(f"4. 5 Concurrent Isolated Tabs Active:             {multi_mem_mb:.2f} MB")
    
    # Clean up
    proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": 99, "method": "shutdown"}) + "\n")
    proc.stdin.flush()
    proc.terminate()
    
    print("\n=== Comparison Benchmark ===")
    print(f"• Headless Engine (Active): ~{heavy_mem_mb:.1f} MB")
    print(f"• Playwright / Chromium:    ~380.0 MB - 600.0 MB  (15x - 25x heavier)")
    print(f"• Puppeteer / Chrome:       ~450.0 MB - 750.0 MB  (18x - 30x heavier)")

if __name__ == "__main__":
    profile_engine()