Skip to content

Notification

sheepie edited this page Mar 6, 2026 · 3 revisions

The extension can periodically send you a summary of your browsing statistics — such as total focus time, visit counts, and sites visited — so you can stay informed without opening the extension manually.

Configuration

All notification settings are available in the Options page under the Notification section.

Setting Values Description
Cycle Off / Daily / Weekly How often to send notifications. Off disables the feature entirely.
Time Time picker (HH:mm) The time of day to trigger the notification. For weekly cycle, also pick a weekday.
Method Browser / HTTP Callback How the notification is delivered.
Callback URL URL (http/https) (Callback only) The endpoint to receive the POST request.
Security Token String (optional) (Callback only) A secret used for HMAC-SHA256 signature verification.

You can click the Test button in the options page to trigger a notification immediately and verify your configuration.

Notification Methods

Browser Notification

When set to Browser, the extension uses the browser's native chrome.notifications API (or equivalent) to show a system notification containing a brief summary:

Time Tracker - Yesterday Focus time: 1h 30min, Visits: 85, Sites: 12

This method requires the browser notifications permission. The extension will request it automatically when sending the first notification. If the user denies the permission request, the notification will fail.

HTTP Callback

When set to HTTP Callback, the extension sends the full browsing statistics to your specified endpoint via an HTTP POST request. This is useful for:

  • Integrating with automation platforms (e.g., Slack, Discord, email services)
  • Storing historical statistics in your own database
  • Building custom dashboards

A demo server implementation is available at examples/notification/demo-server.ts.


Callback Protocol

Endpoint Requirements

  • Must be a valid HTTP or HTTPS URL.
  • Must respond to POST requests with a 2xx status code on success.

Request

Method: POST

Headers:

Header Type Condition Description
Content-Type string Always application/json
Tt4b-Sign string Only when Security Token is configured HMAC-SHA256 signature

Body:

{
  "meta": {
    "locale": "en",       // User locale, e.g. "en", "zh_CN", "ja", "zh_TW", "pt_PT", "uk", "es", "de", "fr"
    "version": "2.5.0",   // Extension version
    "ts": 1709827200000   // Timestamp in milliseconds (Unix epoch)
  },
  "cycle": "daily",       // "daily" or "weekly"
  "summary": {
    "focus": 3600000,     // Total focus time in milliseconds
    "visit": 120,         // Total visit count
    "siteCount": 15,      // Number of unique sites
    "dateStart": "20260306", // Start date (YYYYMMDD)
    "dateEnd": "20260306"   // End date (YYYYMMDD), same as dateStart for daily cycle
  },
  "row": [
    {
      "host": "github.com",
      "date": "20260306",
      "focus": 1800000,   // Focus time in milliseconds
      "time": 30          // Visit count
    }
    // ... more rows
  ]
}

Note: For the weekly cycle, dateStart and dateEnd span a 7-day range (e.g. "20260228" to "20260306"). For daily, both dates are the same.

Signature Verification

If the user has configured a Security Token, each request will include a Tt4b-Sign header. The signature is computed as:

Tt4b-Sign = HMAC-SHA256(meta, securityToken)

Where:

  • meta is the meta field from the request body (the JSON object, serialized in the same form as sent).
  • securityToken is the secret token configured by the user.

To verify:

  1. Extract the meta field from the parsed JSON body.
  2. Compute HMAC-SHA256(meta, securityToken) using your stored token.
  3. Compare the result with the Tt4b-Sign header value.
  4. Reject the request with 401 if they do not match.

If no Security Token is configured, the Tt4b-Sign header will be absent and signature verification can be skipped.

Response

Your server should return:

Status Code Meaning
2xx Success
Other Treated as failure

The response body is ignored by the extension.

Example

Request:

POST /your-callback-url HTTP/1.1
Content-Type: application/json
Tt4b-Sign: a1b2c3d4e5f6...

{
  "meta": {
    "locale": "en",
    "version": "2.5.0",
    "ts": 1709827200000
  },
  "cycle": "daily",
  "summary": {
    "focus": 5400000,
    "visit": 85,
    "siteCount": 12,
    "dateStart": "20260306",
    "dateEnd": "20260306"
  },
  "row": [
    { "host": "github.com", "date": "20260306", "focus": 2400000, "time": 40 },
    { "host": "stackoverflow.com", "date": "20260306", "focus": 1800000, "time": 25 },
    { "host": "google.com", "date": "20260306", "focus": 1200000, "time": 20 }
  ]
}

Response:

HTTP/1.1 200 OK