|
| 1 | +# @grafana/faro-instrumentation-replay |
| 2 | + |
| 3 | +Faro instrumentation for session replay with rrweb. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @grafana/faro-instrumentation-replay |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { ReplayInstrumentation } from '@grafana/faro-instrumentation-replay'; |
| 15 | +import { getWebInstrumentations, initializeFaro } from '@grafana/faro-web-sdk'; |
| 16 | + |
| 17 | +initializeFaro({ |
| 18 | + url: 'https://your-faro-endpoint.com', |
| 19 | + instrumentations: [ |
| 20 | + ...getWebInstrumentations(), |
| 21 | + new ReplayInstrumentation({ |
| 22 | + maskInputOptions: { |
| 23 | + password: true, |
| 24 | + email: true, |
| 25 | + }, |
| 26 | + maskAllInputs: false, |
| 27 | + recordCrossOriginIframes: false, |
| 28 | + }), |
| 29 | + ], |
| 30 | +}); |
| 31 | +``` |
| 32 | + |
| 33 | +## Configuration Options |
| 34 | + |
| 35 | +### Privacy & Masking Options |
| 36 | + |
| 37 | +- **`maskAllInputs`** (default: `false`): Whether to mask all input elements |
| 38 | +- **`maskInputOptions`** (default: `{ password: true }`): Fine-grained control over which input types to mask. |
| 39 | + Available options: |
| 40 | + - `password` - Password inputs |
| 41 | + - `text` - Text inputs |
| 42 | + - `email` - Email inputs |
| 43 | + - `tel` - Telephone inputs |
| 44 | + - `number` - Number inputs |
| 45 | + - `search` - Search inputs |
| 46 | + - `url` - URL inputs |
| 47 | + - `date`, `datetime-local`, `month`, `week`, `time` - Date/time inputs |
| 48 | + - `color` - Color inputs |
| 49 | + - `range` - Range inputs |
| 50 | + - `textarea` - Textarea elements |
| 51 | + - `select` - Select dropdowns |
| 52 | +- **`maskTextSelector`**: Custom CSS selector to mask specific elements |
| 53 | +- **`blockSelector`**: CSS selector to completely block elements from recording |
| 54 | +- **`ignoreSelector`**: CSS selector to ignore specific elements |
| 55 | + |
| 56 | +### Recording Options |
| 57 | + |
| 58 | +- **`recordCrossOriginIframes`** (default: `false`): Whether to record cross-origin iframes |
| 59 | +- **`recordCanvas`** (default: `false`): Whether to record canvas elements |
| 60 | +- **`collectFonts`** (default: `false`): Whether to collect font files |
| 61 | +- **`inlineImages`** (default: `false`): Whether to inline images in the recording |
| 62 | +- **`inlineStylesheet`** (default: `false`): Whether to inline stylesheets |
| 63 | + |
| 64 | +### Hooks |
| 65 | + |
| 66 | +- **`beforeSend`**: Custom function to transform or filter events before they are sent. |
| 67 | + Return the modified event or `null`/`undefined` to skip sending |
| 68 | + |
| 69 | +## Privacy and Security |
| 70 | + |
| 71 | +This instrumentation records user interactions on your website. Make sure to: |
| 72 | + |
| 73 | +1. **Enable appropriate masking options** - By default, only password inputs are masked. |
| 74 | + Configure `maskInputOptions` to mask additional sensitive fields |
| 75 | +2. **Use CSS selectors** - Use `maskTextSelector` to mask sensitive content, `blockSelector` to completely exclude elements |
| 76 | +3. **Implement filtering** - Use the `beforeSend` hook to filter or transform events before sending |
| 77 | +4. **Review your privacy policy** - Ensure you have proper user consent for session recording |
| 78 | +5. **Test your configuration** - Verify no sensitive information is captured in recordings |
| 79 | + |
| 80 | +### Example: Advanced Privacy Configuration |
| 81 | + |
| 82 | +```typescript |
| 83 | +new ReplayInstrumentation({ |
| 84 | + // Mask all text and email inputs, but allow number inputs |
| 85 | + maskInputOptions: { |
| 86 | + password: true, |
| 87 | + text: true, |
| 88 | + email: true, |
| 89 | + tel: true, |
| 90 | + textarea: true, |
| 91 | + }, |
| 92 | + // Mask elements with specific CSS classes |
| 93 | + maskTextSelector: '.sensitive-data, .pii', |
| 94 | + // Block elements completely from recording |
| 95 | + blockSelector: '.payment-form, .credit-card-info', |
| 96 | + // Ignore certain elements (won't be recorded at all) |
| 97 | + ignoreSelector: '.analytics-widget', |
| 98 | + // Filter or transform events before sending |
| 99 | + beforeSend: (event) => { |
| 100 | + // Example: Skip events that might contain sensitive data |
| 101 | + if (event.type === 3 && event.data?.source === 'CanvasMutation') { |
| 102 | + return null; // Skip this event |
| 103 | + } |
| 104 | + return event; // Send the event as-is |
| 105 | + }, |
| 106 | +}); |
| 107 | +``` |
0 commit comments