How sathiyasenpai/vectortrace works
Purpose and Runtime Shape
VectorTrace is a Manifest V3 Chrome extension for locally defining, executing, and repairing webpage extraction schemas. WXT builds separate extension contexts: MV3 service worker, injected content script, React popup/options pages, and an offscreen document for WASM inference. Primary entry points are src/entrypoints/background.ts, src/entrypoints/content.ts, and src/entrypoints/offscreen/index.ts.
User-Facing Control Surfaces
The toolbar popup drives schema creation, field selection, extraction, result review, exports, and healing actions. Its stateful workflows are separated into hooks for schema, extraction, change detection, and auto-healing: src/entrypoints/popup/App.tsx, src/popup/hooks/useExtraction.ts, src/popup/hooks/useAutoHeal.ts. The options UI manages persistent preferences, including healing behavior: src/entrypoints/options/App.tsx, src/shared/settings.ts.
Page Capture and Extraction Boundary
The content script is the only layer operating directly on target-page DOMs. It presents visual picking, derives robust CSS/XPath selectors, and extracts/normalizes visible text. Popup requests cross into the content context through messaging; selectors are evaluated CSS-first with XPath fallback. Core paths: src/content/element-picker.ts, src/content/selector-generator.ts, src/content/text-extractor.ts.
Background Orchestration and Messaging
The service worker is the control-plane router between popup, content script, storage, and the offscreen model host. Shared message contracts isolate extension contexts and avoid direct DOM/model access from UI code. Relevant boundaries are src/entrypoints/background.ts, src/shared/messaging.ts, and src/popup/utils/messaging.ts.
Change Detection and Semantic Healing
Extraction compares current selector output with captured expectations to distinguish valid extraction, broken selectors, hidden/empty content, and content drift. On failure, the system enumerates candidate visible text elements, generates embeddings, cosine-ranks candidates against the saved field vector, and can apply a confidence-qualified replacement selector. Similarity logic and healing history are concentrated in src/background/similarity.ts, src/popup/hooks/useChangeDetection.ts, and src/shared/heal-tracker.ts.
Local ML Execution
Embedding inference uses Hugging Face Transformers/ONNX Runtime Web with the 384-dimensional all-MiniLM-L6-v2 model. Because MV3 service workers cannot host the needed WASM/DOM runtime, background orchestration delegates inference to the offscreen document, which self-warms on creation. The model pipeline is src/background/embedding-pipeline.ts; runtime host is src/entrypoints/offscreen/index.ts; plugins/vite-plugin-onnx-bundle.ts packages ONNX/WASM assets.
Persistence and External Dependencies
All operational data remains browser-local: schemas and settings use chrome.storage.local; embeddings use IndexedDB to accommodate larger vectors; heal records preserve selector migrations. No backend, API, or telemetry service is part of the current architecture. Persistence abstractions are src/shared/chrome-storage.ts, src/shared/idb-store.ts, and src/shared/types.ts. Required browser infrastructure includes storage, unlimitedStorage, offscreen, scripting/tab access, and <all_urls> host permissions.
Main entry points: background.ts MV3 Service Worker · App.tsx Toolbar Popup · content.ts Content Script · useExtraction.ts Extraction Workflow
Components 18
Extension UI
- Toolbar Popup · Drives schema, extraction, review, export, and healing workflows.
src/entrypoints/popup/App.tsx - Extraction Workflow
src/popup/hooks/useExtraction.ts - Detection & Healing · Compares results and initiates confidence-qualified repairs.
src/popup/hooks/useChangeDetection.ts - Auto-Heal Actions
src/popup/hooks/useAutoHeal.ts - Options UI · Manages persistent preferences including healing behavior.
src/entrypoints/options/App.tsx
Target Page Boundary
- Content Script · Only extension context that directly accesses target-page DOMs.
src/entrypoints/content.ts - Visual Element Picker
src/content/element-picker.ts - Selector Generation · Generates robust CSS/XPath selectors.
src/content/selector-generator.ts - Text Extraction · Evaluates CSS first with XPath fallback and normalizes visible text.
src/content/text-extractor.ts
Control Plane
- MV3 Service Worker · Routes requests among UI, page, storage, and offscreen inference.
src/entrypoints/background.ts - Message Contracts · Isolates extension contexts from direct DOM and model access.
src/shared/messaging.ts
Local ML
- Embedding Pipeline · Produces 384-dimensional all-MiniLM-L6-v2 embeddings.
src/background/embedding-pipeline.ts - Offscreen Model Host · Self-warms and hosts Transformers/ONNX inference outside the service worker.
src/entrypoints/offscreen/index.ts - Candidate Ranking · Cosine-ranks visible-text candidates against saved field vectors.
src/background/similarity.ts
Local Persistence
- Schemas & Settings
src/shared/chrome-storage.ts - Embedding Store · Stores larger saved field vectors locally.
src/shared/idb-store.ts - Heal History · Preserves selector migrations.
src/shared/heal-tracker.ts - Healing Preferences
src/shared/settings.ts
Connections 21
- Toolbar Popup → Extraction Workflow: uses
- Toolbar Popup → Detection & Healing: uses
- Toolbar Popup → Auto-Heal Actions: uses
- Options UI → Healing Preferences: edits
- Extraction Workflow → MV3 Service Worker: requests extraction
- Detection & Healing → MV3 Service Worker: requests detection
- Auto-Heal Actions → MV3 Service Worker: requests repair
- MV3 Service Worker → Message Contracts: uses
- MV3 Service Worker → Content Script: routes page commands
- Content Script → Visual Element Picker: presents
- Visual Element Picker → Selector Generation: selected element
- Content Script → Text Extraction: extracts through
- Text Extraction → Selector Generation: evaluates
- MV3 Service Worker → Embedding Pipeline: delegates embeddings
- Embedding Pipeline → Offscreen Model Host: runs inference in
- MV3 Service Worker → Candidate Ranking: ranks repair candidates
- Candidate Ranking → Embedding Store: reads saved vectors
- MV3 Service Worker → Schemas & Settings: reads and writes
- MV3 Service Worker → Embedding Store: persists embeddings
- MV3 Service Worker → Heal History: records migrations
- Healing Preferences → Schemas & Settings: stored in