# AutoFiller Universal **Batch-fill any web form from a spreadsheet — deterministically, with no LLM in the loop at the moment that matters.** [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) [![tests](https://img.shields.io/badge/tests-14%2F14%20passing-brightgreen.svg)](#testing) [![Playwright](https://img.shields.io/badge/playwright-CDP%20attach-orange.svg)](https://playwright.dev/) Point it at an Excel/CSV/JSON file and a form. Everything specific to a given form lives in **one JSON file** — the *recipe*. The engine, the launcher and the safety guards never change. --- ## The problem Public-administration portals often run **click-days**: a funding window opens at 09:00:00 and closes when the budget is exhausted, sometimes minutes later. Behind the SPID login there are hundreds of near-identical records to type into a modal form — name, surname, date of birth, tax code, cascading province/municipality selects — one at a time, by hand, under time pressure. Three things go wrong: 1. **Speed.** Manual typing costs ~40 seconds per record. 150 records is 100 minutes. 2. **Accuracy.** One mistyped tax code and the record is rejected — sometimes the whole application. 3. **Fragility.** Naive automation breaks the moment the portal ships a new build and every `id` changes, and it breaks *silently*. Generic RPA tools want to own the browser session. That does not work when the session sits behind an interactive SPID/CIE login and ends in a legally binding submission. AutoFiller takes the opposite approach: **you** own the browser and the final click; it only types. --- ## How it works Two phases, with a hard rule between them: **the LLM is used offline, never at click-day.** Phase 2 is pure deterministic DOM work — no network calls, no model latency, no non-determinism. ``` ┌──────────────────────────── PHASE 1 — offline, once per form ────┐ DATA │ │ .xlsx │ recipe_maker.py │ .csv ──┼──▶ reads the live DOM over CDP │ .json │ ├─ (default) LLM maps headers → selectors │ │ ├─ --auto zero-LLM semantic matching (label/name/synonyms) │ │ └─ --pick point & click panel in the browser │ │ │ │ │ ▼ │ │ recipe.json + field fingerprints + form.snapshot.html │ └───────────┬──────────────────────────────────────────────────────┘ │ ┌───────────▼──────────── validation, still offline ───────────────┐ │ rehearsal.py replays ALL records against the HTML snapshot │ │ check_data.py tax-code checksums, dates, duplicates, and every │ │ value matched against the REAL select options │ └───────────┬──────────────────────────────────────────────────────┘ │ ┌───────────▼──────────── PHASE 2 — click-day, N records ──────────┐ │ launcher.py attaches to YOUR Chrome (CDP :9222, already │ │ logged in via SPID) and injects engine.js │ │ │ │ for each record: add ▸ fillWith(record, recipe) ▸ save │ │ ZERO LLM · dialog guard · run log · resume │ │ STOPS before confirm / sign / submit │ └───────────────────────────────────────────────────────────────────┘ ``` ```mermaid flowchart LR D[("Excel / CSV / JSON")] --> RM[recipe_maker.py
LLM · --auto · --pick] DOM[("Live DOM via CDP")] --> RM RM --> R[["recipe.json
+ fingerprints"]] RM --> S[["form.snapshot.html"]] R --> CD[check_data.py
pre-flight] S --> RH[rehearsal.py
offline dry run] D --> CD D --> RH R --> L[launcher.py] L -->|injects| E[[engine.js
~1000 LOC, no LLM]] E --> C(("Your Chrome
SPID session")) L -.->|never clicks| X{{confirm · sign · submit}} ``` * **`engine.js`** — one engine for every form. Injected once, then `window.__AUTOFILL__.fillWith(record, recipe)` per record. Handles text, native `` widgets: the engine opens the widget, types if needed, and clicks the matching option (override with `optionSelector`). * `dynamic: true` + `parent`: AJAX cascade (municipality loaded after province). `fillOrder` puts parents before their dependent children. * `transform`: `uppercase` | `lowercase` | `date_dd_mm_yyyy` | `date_yyyy_mm_dd`. * `fp`: fingerprint used by the self-healing ladder. `tokens`: fuzzy fallback. * `timing`: per-recipe speed override (defaults are deliberately conservative). * `flow` (optional, used by `pilot.py`): a declarative navigation script built from `goto` | `click` | `waitFor` | `waitHidden` | `fill` | `type` | `upload` | `sleep` | `pause`, with `{header}` interpolation from the current record. Ready-made examples: `recipes/demo_clone.json` (modal form) and `recipes/demo_clone_flow.json` (full navigation from the home page). --- ## Quick start ```powershell # 0. install pip install -r requirements.txt playwright install chromium # 1. open a real Chrome with the debug port, log in (SPID/CIE), reach the form ./start_chrome.ps1 # 2. build the recipe once, with the form open in that Chrome python recipe_maker.py --data my_data.xlsx --sheet Sheet1 # --auto no LLM: semantic header <-> field matching # --pick no LLM: point & click panel inside the browser # also writes: per-field fingerprints + .snapshot.html # 3. validate offline — twice, both free python rehearsal.py recipes/my_data.json my_data.xlsx --sheet Sheet1 python check_data.py recipes/my_data.json my_data.xlsx --sheet Sheet1 # 4. click-day python launcher.py recipes/my_data.json my_data.xlsx --sheet Sheet1 --at 09:00:00 ``` Run the whole loop with zero setup against the bundled offline form: ```powershell python check_data.py recipes/demo_clone.json sample_data.csv python test_e2e_clone.py ``` Phase 1 needs a model only in default mode: local **Ollama** (`ollama serve`, model in `config.py`, override with `OLLAMA_MODEL`), or `AUTOFILL_LLM_PROVIDER=openrouter|gemini` with the API key from the environment. `--auto` and `--pick` need no model at all. --- ## Commands | Command | What it does | |---|---| | `python recipe_maker.py --data F` | Phase 1: read the live DOM, produce `recipes/F.json` + fingerprints + snapshot | | `… --auto` | Zero-LLM semantic mapping; ambiguous headers are left out | | `… --pick` | Zero-LLM point & click mapping panel in the browser | | `python rehearsal.py R D` | Offline dress rehearsal: all records against the HTML snapshot | | `python check_data.py R D` | Pre-flight: tax-code checksums, dates, duplicates, values vs real options | | `python launcher.py R D` | Phase 2: attach to Chrome, fill and save every record | | `python pilot.py R D` | Launcher superset: also *navigates* (declarative `flow`), can drive its own browser (`--launch`, `--profile`, `--url`) | | `python app.py` | Local control panel: load data, map fields, assist and demo modes | | `python load_data.py` | Loader self-check | Launcher/pilot flags: `--dry` (fill, don't save) · `--start N` · `--resume` · `--limit N` · `--stop-on-fail` · `--match TEXT` (pick the right tab) · `--at HH:MM:SS` · `--no-shots` · `--assist`. --- ## Testing Fourteen executable checks run against a bundled offline form clone (`test_frontends/`) — no portal, no login, no network: ```powershell python load_data.py # loader self-check python check_data.py # pre-flight self-check (tax-code checksums) python test_engine.py # engine smoke test: text / select / date fields python test_healing.py # every id renamed → 7/7 fields resolved via fingerprint python test_guard.py # dialog guard, post-save verify, healing, resume python test_e2e_clone.py # full add → fill → save over multiple records python test_pilot.py # real-click navigation + partial fill + upload python test_assist.py # assist: focus → menu → filter → click → fill python test_demo.py # demo mode: 1st record by hand → map inferred → replay python test_rehearsal.py # offline rehearsal over all sample records python test_autorecipe.py # --auto zero-LLM mapping python test_mapper.py # point & click recipe builder python test_combo.py # custom (non-