A Record & Replay browser automation engine inspired from 100X Bot
The system is composed of three distinct phases:
- Core Library:
rrweb(record-replay-web) - Mechanism: Captures the DOM mutation stream and user interactions (clicks, inputs, scrolls).
- Context Injection: On critical interaction events (e.g.,
mousedown), the recorder captures a localized, sanitized snapshot of the target element's DOM tree (Parent, Siblings, Attributes) to serve as ground truth for the synthesis engine.
- Runtime: Bun + Hono
- Orchestration: Inngest
- Inference: Gemini 3 Flash
- Process:
- Trace Upload: The client uploads the raw
rrwebtrace and DOM snapshots to the Bun backend. - Selector Generation: Inngest triggers a background job where Gemini 3 Flash analyzes the target element's properties against the DOM snapshot.
- Strategy Compilation: The model generates a ranked list of selector strategies (Reliability Hierarchy:
id>data-testid>aria-label>innerText>XPath). - Artifact Creation: A portable JSON
ReplayManifestis stored, containing the optimized selector logic for each step.
- Mechanism: A lightweight JS injector (
player.js) runs directly in the target tab. - Logic:
- Fetches the
ReplayManifestfrom the backend. - Iterates through the selector strategies for the current step.
- Heuristic Validation: If the primary selector fails (e.g., dynamic class change), the runtime attempts fallback strategies in order.
- Execution: Dispatches trusted
isTrusted: trueevents to the resolved node.
- Runtime Environment: Bun (v1.1+) - Selected for high-throughput HTTP performance and native TypeScript support.
- LLM Provider: Gemini 3 Flash - Utilized for its extensive context window (handling large DOM dumps) and low latency.
- Async Orchestration: Inngest - Manages the non-blocking synthesis pipeline and retries.
- Frontend/Extension: React + Vite (CRXJS) - Chrome Extension manifest v3.
- Database: Supabase (PostgreSQL) - Stores
ReplayManifestsand user configurations.
The core artifact produced by the system is the ReplayManifest. It decouples the execution logic from the specific DOM state of the recording.
interface ReplayStep {
id: string;
action: 'click' | 'input' | 'scroll';
timestamp: number;
target: {
// Primary stable identifier
primarySelector: string;
// Fallback strategies generated by Gemini
strategies: [
{ type: 'id', value: 'ember123' },
{ type: 'attribute', key: 'aria-label', value: 'Connect' },
{ type: 'text_approx', value: 'Connect', threshold: 0.8 },
{ type: 'xpath', value: '//button[contains(@class, "artdeco-button")]' }
];
};
// Pre-condition check (optional)
constraints?: {
requiredText?: string;
urlPattern?: string;
};
}- Bun v1.1+
- Google AI Studio API Key (Gemini 3 Flash enabled)
- Supabase Project (or local Postgres)
- Clone and Install
git clone https://github.com/laxman-0/r-squared.git
cd r-squared
bun install
- Environment Configuration
Create a
.envfile in the root:
GEMINI_API_KEY=your_key_here
INNGEST_EVENT_KEY=local_dev
DATABASE_URL=postgres://user:pass@localhost:5432/rsquared
- Start Services Backend (Bun + Inngest):
bun run dev:server
Extension Watch Mode:
bun run watch:ext
Inngest Dev Server:
npx inngest-cli@latest dev
- Load Extension
- Navigate to
chrome://extensions. - Enable Developer Mode.
- Click Load Unpacked and select the
dist/directory.
Uploads a raw recording session.
Payload:
{
"sessionId": "uuid",
"url": "https://linkedin.com/in/...",
"events": [ ...rrweb_events ]
}
Retrieves the compiled ReplayManifest for execution.
Response:
{
"status": "ready",
"manifest": { ...ReplayManifest }
}
- DOM Sanitization: To reduce token usage, the synthesis engine strips standard HTML attributes (style, width, height) that do not contribute to semantic identity before sending the DOM tree to Gemini.
- Latency Optimization: The synthesis phase is decoupled from recording. The user can stop recording and immediately receive a "Processing..." status. Once the Inngest job completes, the extension receives a WebSocket push notification (or polls) to enable the "Replay" button.