Skip to content

feat(session-replay): support local maskTextFn and maskInputFn in privacyConfig - #2200

Draft
jxiwang wants to merge 1 commit into
mainfrom
cursor/custom-mask-text-fn-97fd
Draft

jxiwang wants to merge 1 commit into
mainfrom
cursor/custom-mask-text-fn-97fd

Conversation

@jxiwang

@jxiwang jxiwang commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Draft implementation for SRF-63 (https://linear.app/amplitude/issue/SRF-63/support-custom-text-masking-callbacks-in-browser-session-replay).

Summary

Adds optional, local-only privacyConfig.maskTextFn(text, element) and privacyConfig.maskInputFn(text, element). They replace the default * redaction for content the SDK would already mask (for example defaultMaskLevel: 'conservative'). Behavior is unchanged when they are unset.

Semantics

  • Only called for level-based masking. Never called for blocked elements (rrweb doesn't serialize them), amp-mask / data-amp-mask / maskSelector matches, unmasked content, or password inputs.
  • Fails closed: if the callback throws or returns a non-string, the text is fully redacted.
  • Local-only: parsePrivacyConfig ignores it, and joined-config carries the local callbacks over when a remote privacy config is merged (the joined config is otherwise rebuilt from scratch and would have dropped them).
  • Remote mask levels / urlMaskLevels still decide whether content is masked at all.

Changes

  • session-replay-dom-privacy: new types; isMasked internals now report whether masking was explicit or level-based; maskFn applies callbacks.
  • session-replay-browser: preserve callbacks in joined config.
  • plugin-session-replay-browser: forward the new fields (the plugin copies privacyConfig field by field) and add types.
  • READMEs updated; unit tests added.

Open questions

Testing

  • session-replay-dom-privacy, session-replay-browser, plugin-session-replay-browser: jest passes with coverage thresholds met; lint passes.
  • session-replay-browser pnpm typecheck reports an existing error in e2e/idb.spec.ts, which also occurs without these changes.
Open in Web Open in Cursor 

@github-actions

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 68.56 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 140.99 KB (+0.11% 🔺)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 227.7 KB (+0.08% 🔺)
@amplitude/element-selector (gzipped esm) 3.48 KB (0%)
@amplitude/analytics-browser/lite (gzipped CDN bundle) 21.31 KB (0%)

@github-actions

Copy link
Copy Markdown

Session Replay Browser E2E Results

passed  164 passed
flaky  1 flaky

Details

stats  165 tests across 19 suites
duration  4 minutes, 56 seconds
commit  34cd18d

Flaky tests

chromium › e2e/shadow-dom.spec.ts › captureAdoptedStyleSheets option › SDK initializes without error and captures shadow host with default (true)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants