> ## 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 Sync

> How the Chrome extension scrapes Turo earnings and syncs them to HostMetrics

# Chrome Extension Sync

The HostMetrics Chrome extension provides a one-click alternative to manual CSV downloads. It scrapes trip earnings data directly from Turo's website and sends it to HostMetrics for import.

## What the Extension Does

Instead of downloading a CSV from Turo and uploading it to HostMetrics, the extension:

1. Reads trip earnings data from the Turo dashboard page
2. Packages the data in the same format as a Trip Earnings CSV
3. Sends it to the HostMetrics API for processing
4. Shows sync progress and results in the extension popup

## Installation

The extension can be installed two ways:

* **Chrome Web Store** — Install directly from the store listing
* **Manual install** — Download the ZIP from HostMetrics and load as an unpacked extension in `chrome://extensions`

For step-by-step setup, see [Chrome Extension Setup](/getting-started/chrome-extension).

## Sync Flow

```
User clicks "Sync" in extension popup
→ Content script (turo-earnings.js) scrapes Turo page
→ Data sent to service worker (service-worker.js)
→ Service worker posts to HostMetrics API
→ API runs same import pipeline as CSV upload
→ Extension shows success/error result
```

<Accordion title="Content Scripts">
  * `turo-earnings.js` — Scrapes trip earnings data from the Turo earnings page
  * `turo-page-interceptor.js` — Intercepts Turo API responses for additional data capture
  * `hostmetrics-bridge.js` — Bridges communication between the Turo page context and the extension
</Accordion>

<Accordion title="Background Service Worker">
  `service-worker.js` handles the extension lifecycle, manages authentication state, and coordinates data transfer between content scripts and the HostMetrics API.
</Accordion>

<Accordion title="Popup UI">
  `popup.js` renders the extension popup with sync button, progress bar, last sync timestamp, and error messages.
</Accordion>

## Progress Tracking

During sync, the extension popup shows:

* Current step (reading data, sending to server, processing)
* Progress percentage
* Number of trips found
* Estimated time remaining

## Error States

| Error                   | Cause                                         | Resolution                                |
| ----------------------- | --------------------------------------------- | ----------------------------------------- |
| **Turo login required** | User is not logged in to Turo                 | Log in to Turo in the same browser        |
| **Network error**       | Cannot reach HostMetrics API                  | Check internet connection, verify API URL |
| **No data found**       | Extension could not find earnings on the page | Navigate to the Turo earnings page first  |
| **Import failed**       | Server-side processing error                  | Check HostMetrics for error details       |

<Note>
  The extension requires the user to be on the Turo earnings page (`turo.com/us/en/account/earnings`) for the scrape to work. The extension popup will prompt navigation if needed.
</Note>

## Last Sync Display

The `TuroSyncStatus` component on the Data Sources page shows:

* Last successful sync timestamp
* Number of trips synced
* Sync source (extension vs manual CSV)

The `ExtensionSyncButton` component provides an in-app trigger that communicates with the installed extension.

## Extension Files

| File                                                | Purpose                                   |
| --------------------------------------------------- | ----------------------------------------- |
| `chrome-extension/background/service-worker.js`     | Extension lifecycle and API communication |
| `chrome-extension/content/turo-earnings.js`         | Turo page scraping logic                  |
| `chrome-extension/content/turo-page-interceptor.js` | API response interception                 |
| `chrome-extension/content/hostmetrics-bridge.js`    | Page-to-extension bridge                  |
| `chrome-extension/popup/popup.js`                   | Extension popup UI                        |
| `chrome-extension/lib/config.js`                    | API URL and extension configuration       |

## Security

The extension only accesses Turo pages (declared in the manifest permissions). Data is sent exclusively to the HostMetrics API over HTTPS. No credentials are stored in the extension — it uses the user's existing Turo browser session.
