feat(core): add capture config to decide what gets recorded#49
Merged
Conversation
`capture(req) => boolean | string` is a single knob for what becomes an event: false skips, true records a "pageView", a string records that event type. It sees only real browser navigations and direct (non-browser) GETs — RSC/XHR sub-requests, prefetches, static assets and non-GET writes are filtered before it — and exposes `fromBrowser` to tell humans from agents/crawlers/curl. It replaces isApiPath + excludeApiCalls + excludePaths, which are now deprecated but still work; a warning is logged if they're combined with `capture` (capture wins). The demo site is migrated to `capture`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A single, dev-friendly knob for what becomes an event — replacing
isApiPath+excludeApiCalls+excludePaths(now deprecated, still working).captureonly sees the requests that could be events — real browsernavigations and direct (non-browser) GETs. RSC/XHR sub-requests, prefetches,
static assets, and non-GET writes are filtered before it, so consumers never
deal with the RSC-duplicate / method nuances.
fromBrowserdistinguishes realusers from agents/crawlers/curl (no
Sec-Fetch-*).Example
This also fixes the scanner-404 noise: an unknown path simply isn't allowlisted, so the library never needs to know whether a route exists.
Backward compatibility
isApiPath/excludeApiCalls/excludePathsare marked@deprecatedbutfully functional — when
captureis absent the old code path runs unchanged. Awarning is logged if they're combined with
capture(capture wins). The demosite is migrated to
capture.Tests
capture.test.ts(5 unit tests) forresolveCaptureType.🤖 Generated with Claude Code