> ## Documentation Index
> Fetch the complete documentation index at: https://dhanurgo.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Chrome Extension

> Build and load the HostMetrics Chrome extension for Turo data sync

# Chrome Extension Setup

The HostMetrics Chrome extension automatically syncs trip earnings data from Turo's website.

## Extension Architecture

The extension consists of:

* **Service Worker** (`background/service-worker.js`) — Orchestrates sync
* **Content Scripts** — Intercept Turo page data
* **Popup UI** — User interface for triggering sync
* **Bridge Script** — Communicates between extension and HostMetrics web app

## Loading the Extension (Development)

1. Open Chrome and navigate to `chrome://extensions`
2. Enable **Developer mode** (toggle in top-right)
3. Click **Load unpacked**
4. Select the `chrome-extension/` directory from the project root
5. The extension icon should appear in your toolbar

## How Sync Works

1. User clicks "Sync" in the HostMetrics web app (or extension popup)
2. Extension navigates to Turo's earnings page
3. Content script intercepts the page data
4. Data is sent to HostMetrics via `POST /api/turo/sync`
5. Server parses CSV, deduplicates, and inserts records

## Communication Flow

```mermaid theme={null}
sequenceDiagram
    participant App as HostMetrics Web App
    participant Bridge as Bridge Content Script
    participant SW as Service Worker
    participant CS as Turo Content Script
    participant Turo as Turo.com

    App->>Bridge: CustomEvent (hm:start-sync)
    Bridge->>SW: chrome.runtime.sendMessage
    SW->>CS: chrome.tabs.sendMessage
    CS->>Turo: Intercept page data
    Turo-->>CS: CSV data
    CS-->>SW: CSV content
    SW->>App: POST /api/turo/sync
    App-->>App: Parse, deduplicate, insert
    App->>Bridge: CustomEvent (hm:sync-success)
```

## Distributing the Extension

For non-developers, the extension is distributed as a `.zip` file:

1. Zip the `chrome-extension/` directory
2. Place at `public/downloads/hostmetrics-turo-sync.zip`
3. Users download from the Data Sources page and load it manually

<Warning>
  The extension requires the user to be logged into both Turo and HostMetrics. If the Turo session expires, the sync will emit a `hm:turo-login-required` event.
</Warning>
