# Sony PDE Helper Chrome Extension

A Chrome extension that extracts and copies authentication tokens, user identities, emails, and Datadog RUM session links from PDE systems with just one click. Ships with three UI themes (Dark, Light, Matrix).

## Features

- **🔑 Bearer Token** - Authentication token for API requests (with expiration validation and time-left indicator). The ▾ button expands the decoded JWT payload right in the popup — no more pasting tokens into jwt.io
- **📝 Raw Headers** - Captured Orchard/Apollo request headers; the side button switches the copy format between plain text, JSON, and .env (choice is remembered)
- **👤 Identity UUID** - User identity identifier from Datadog RUM
- **📧 Email** - User email from Datadog RUM  
- **📊 Datadog RUM Link** - Direct link to session replay for debugging; the ↗ button opens it in a new tab

The popup shows the current state up front: token validity with time left, captured header count, and previews of identity, email, and RUM link — before you click anything.

Tokens and headers are tracked **per environment (QA / PROD)**, so tabs from different environments never overwrite each other. The popup always serves the token matching the active tab's environment and labels it (`QA · 42m left`), and notes when the other environment also has a token. The toolbar badge shows the freshest token's state (green ✓ = valid, red ! = expired).

## Installation

1. Clone this repository
2. Open Chrome and navigate to `chrome://extensions/`
   ![Extensions page](readme-images/extensions.png)
3. Enable "Developer mode" toggle in the top right
   ![Developer mode](readme-images/developer-mode.png)
4. Click "Load unpacked" and select the `sony-pde-token-chrome-ext` directory
   ![Load unpacked](readme-images/load.png)

## Usage

1. Navigate to any supported Sony PDE system
2. Click the Sony PDE Helper extension icon in the Chrome toolbar
3. Click any of the five buttons to copy data to clipboard:
   - **Token** - Bearer token (shows environment and time remaining if valid)
   - **Raw Headers** - Captured request headers in the selected format
   - **Identity** - User identity UUID
   - **Email** - User email address
   - **Datadog RUM Link** - Session replay link

The extension automatically disables buttons on unsupported sites and shows clear status messages for each action.

## Settings

Open the settings via the ⚙ icon in the popup. Available options:

- **Theme** — Dark (default), Light, or Matrix. Applies to the popup and the shortcut toast. With the Matrix theme the popup title becomes "Sony PDE Helper Neo".
- **Keyboard shortcuts** (off by default) — copy values without opening the popup; a toast on the page confirms the copy. Combinations are changeable at `chrome://extensions/shortcuts`:
  - Token — `Ctrl+Shift+K` / `⌘⇧K` (works on any page)
  - Identity UUID — `Ctrl+Shift+U` / `⌘⇧U` (PDE pages only)
  - Email — `Ctrl+Shift+E` / `⌘⇧E` (PDE pages only)

## Usage Analytics (GA4)

The extension can send anonymous usage events (popup opens, button clicks, keyboard-shortcut usage) to Google Analytics 4 via the Measurement Protocol. Only event names, the extension version, and a random install id are sent — never tokens, emails, or identity UUIDs.

To enable:

1. Create a GA4 property with a **Web** data stream at https://analytics.google.com
2. Copy the **Measurement ID** (`G-XXXXXXXXXX`) from the data stream page
3. On the same page, open **Measurement Protocol API secrets** and create a secret
4. Put both values into `CONSTANTS.ANALYTICS` in `constants.js`

Tracking stays disabled while `MEASUREMENT_ID` or `API_SECRET` is empty.
