@goliapkg/sentori-react-native 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +131 -0
- package/README.md +40 -30
- package/android/src/main/java/com/sentori/SentoriModule.kt +8 -0
- package/android/src/main/java/com/sentori/SentoriScreenshotCapture.kt +36 -4
- package/ios/SentoriCrashHandler.swift +48 -4
- package/ios/SentoriModule.swift +12 -0
- package/ios/SentoriScreenshotCapture.swift +34 -3
- package/lib/config.d.ts +1 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/init.d.ts.map +1 -1
- package/lib/init.js +18 -6
- package/lib/init.js.map +1 -1
- package/lib/mask.d.ts +8 -0
- package/lib/mask.d.ts.map +1 -0
- package/lib/mask.js +35 -0
- package/lib/mask.js.map +1 -0
- package/lib/native.d.ts +4 -11
- package/lib/native.d.ts.map +1 -1
- package/lib/native.js +23 -0
- package/lib/native.js.map +1 -1
- package/lib/rage-tap.d.ts.map +1 -1
- package/lib/rage-tap.js +30 -2
- package/lib/rage-tap.js.map +1 -1
- package/lib/replay-screens.d.ts +15 -0
- package/lib/replay-screens.d.ts.map +1 -0
- package/lib/replay-screens.js +87 -0
- package/lib/replay-screens.js.map +1 -0
- package/lib/responsiveness-detector.d.ts +18 -0
- package/lib/responsiveness-detector.d.ts.map +1 -0
- package/lib/responsiveness-detector.js +55 -0
- package/lib/responsiveness-detector.js.map +1 -0
- package/package.json +3 -2
- package/src/__tests__/replay-screens.test.ts +63 -0
- package/src/__tests__/responsiveness-detector.test.ts +74 -0
- package/src/config.ts +1 -0
- package/src/index.ts +3 -0
- package/src/init.ts +27 -9
- package/src/mask.ts +39 -0
- package/src/native.ts +33 -0
- package/src/rage-tap.tsx +46 -2
- package/src/replay-screens.ts +95 -0
- package/src/responsiveness-detector.ts +66 -0
package/src/init.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { checkColdStart } from './mobile-vitals';
|
|
|
17
17
|
import { markNativeJsBridgeReady, setNativeConfig } from './native';
|
|
18
18
|
import { shipNativePending } from './native-pending';
|
|
19
19
|
import { drainReplay, startReplay } from './replay';
|
|
20
|
+
import { drainScreenReplay, startScreenReplay } from './replay-screens';
|
|
20
21
|
import { drainOfflineQueue, startTransport, uploadAttachment } from './transport';
|
|
21
22
|
|
|
22
23
|
let _initialized = false;
|
|
@@ -50,6 +51,7 @@ export const init = safeFn('init', (config: InitConfig): void => {
|
|
|
50
51
|
slowApi: config.detect?.slowApi ?? false,
|
|
51
52
|
},
|
|
52
53
|
replaySeconds: config.replaySeconds ?? 30,
|
|
54
|
+
replayScreens: config.replayScreens ?? false,
|
|
53
55
|
beforeSend: config.beforeSend,
|
|
54
56
|
});
|
|
55
57
|
setLogLevel(config.logLevel ?? 'warn');
|
|
@@ -69,19 +71,35 @@ export const init = safeFn('init', (config: InitConfig): void => {
|
|
|
69
71
|
const replaySeconds = config.replaySeconds ?? 30;
|
|
70
72
|
if (replaySeconds > 0) {
|
|
71
73
|
startReplay({ mode: 'wireframe' });
|
|
74
|
+
// Visual ring is opt-in: screenshots can carry user content.
|
|
75
|
+
if (config.replayScreens === true) startScreenReplay(replaySeconds);
|
|
72
76
|
registerEmitHook((event) => {
|
|
73
77
|
if (event.kind !== 'error' && event.kind !== 'warn') return;
|
|
74
78
|
if (!event.id) return;
|
|
75
79
|
const lines = drainReplay();
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
if (lines) {
|
|
81
|
+
const base64 = base64Encode(lines);
|
|
82
|
+
if (base64) {
|
|
83
|
+
void uploadAttachment(
|
|
84
|
+
event.id,
|
|
85
|
+
'replay',
|
|
86
|
+
{ base64, mediaType: 'application/x-sentori-replay' },
|
|
87
|
+
{ source: 'js' },
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const frames = drainScreenReplay();
|
|
92
|
+
if (frames) {
|
|
93
|
+
const base64 = base64Encode(frames);
|
|
94
|
+
if (base64) {
|
|
95
|
+
void uploadAttachment(
|
|
96
|
+
event.id,
|
|
97
|
+
'screens',
|
|
98
|
+
{ base64, mediaType: 'application/x-sentori-screens' },
|
|
99
|
+
{ source: 'js' },
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
85
103
|
});
|
|
86
104
|
}
|
|
87
105
|
|
package/src/mask.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Screen masking — the privacy half of visual replay.
|
|
2
|
+
//
|
|
3
|
+
// The host registers a query returning the `nativeID`s of views
|
|
4
|
+
// that must never appear in a screenshot (camera feeds, user
|
|
5
|
+
// identity, payment fields). Native paints black rectangles over
|
|
6
|
+
// those subtrees in the same render pass, so the pixels never
|
|
7
|
+
// leave the device.
|
|
8
|
+
//
|
|
9
|
+
// The query runs on every frame tick; keep it cheap (return a
|
|
10
|
+
// cached array). A throwing query is swallowed and masks NOTHING
|
|
11
|
+
// that tick — so a broken query fails visible-in-review rather
|
|
12
|
+
// than silently, and can never take the capture path down.
|
|
13
|
+
|
|
14
|
+
import { reportInternal } from '@goliapkg/sentori-core';
|
|
15
|
+
|
|
16
|
+
type MaskQuery = () => string[];
|
|
17
|
+
|
|
18
|
+
let _query: MaskQuery | null = null;
|
|
19
|
+
|
|
20
|
+
/** Register (or with `null`, clear) the mask query. */
|
|
21
|
+
export const registerMaskQuery = (query: MaskQuery | null): void => {
|
|
22
|
+
_query = query;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** The current mask list; empty when unregistered or throwing. */
|
|
26
|
+
export const maskedNativeIds = (): string[] => {
|
|
27
|
+
if (!_query) return [];
|
|
28
|
+
try {
|
|
29
|
+
const ids = _query();
|
|
30
|
+
return Array.isArray(ids) ? ids.filter((x) => typeof x === 'string') : [];
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reportInternal('mask-query', e);
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const __resetForTests = (): void => {
|
|
38
|
+
_query = null;
|
|
39
|
+
};
|
package/src/native.ts
CHANGED
|
@@ -69,6 +69,13 @@ type SentoriNativeModule = {
|
|
|
69
69
|
* snapshot string or null on failure.
|
|
70
70
|
*/
|
|
71
71
|
captureWireframe?: (maskedIds: string[]) => null | string
|
|
72
|
+
|
|
73
|
+
/** v5.1 — low-bitrate replay frame; absent on older native builds. */
|
|
74
|
+
captureReplayFrame?: (
|
|
75
|
+
maskedIds: string[],
|
|
76
|
+
longEdgePx: number,
|
|
77
|
+
quality: number,
|
|
78
|
+
) => Promise<null | { base64: string; mediaType: string }>
|
|
72
79
|
/**
|
|
73
80
|
* v0.9.12 — diagnostic readout for the wireframe path. Cheap
|
|
74
81
|
* synchronous call that returns the path the last `captureWireframe`
|
|
@@ -387,6 +394,32 @@ export function getRecentNativeException(): null | {
|
|
|
387
394
|
* Callers must treat `null` as "no screenshot this round" — the
|
|
388
395
|
* error event still ships, just without a thumbnail.
|
|
389
396
|
*/
|
|
397
|
+
/** v5.1 — one low-bitrate frame for the screens replay ring.
|
|
398
|
+
* Null on every failure mode (module unbound, method missing on an
|
|
399
|
+
* older native build, capture failed); the ring just skips a beat. */
|
|
400
|
+
let warnedNoReplayFrame = false
|
|
401
|
+
export async function captureNativeReplayFrame(
|
|
402
|
+
maskedIds: string[],
|
|
403
|
+
longEdgePx: number,
|
|
404
|
+
quality: number,
|
|
405
|
+
): Promise<null | { base64: string; mediaType: string }> {
|
|
406
|
+
const n = native()
|
|
407
|
+
if (!n) return null
|
|
408
|
+
if (!n.captureReplayFrame) {
|
|
409
|
+
if (!warnedNoReplayFrame) {
|
|
410
|
+
warnedNoReplayFrame = true
|
|
411
|
+
logger.warn('native', 'captureReplayFrame missing — rebuild the native app for visual replay')
|
|
412
|
+
}
|
|
413
|
+
return null
|
|
414
|
+
}
|
|
415
|
+
try {
|
|
416
|
+
return (await n.captureReplayFrame(maskedIds, longEdgePx, quality)) ?? null
|
|
417
|
+
} catch (e) {
|
|
418
|
+
logger.warn('native', 'captureReplayFrame threw', e)
|
|
419
|
+
return null
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
390
423
|
export async function captureNativeScreenshotWithMask(
|
|
391
424
|
maskedIds: string[],
|
|
392
425
|
): Promise<null | { base64: string; mediaType: string }> {
|
package/src/rage-tap.tsx
CHANGED
|
@@ -13,11 +13,18 @@
|
|
|
13
13
|
import React, { useCallback, useRef } from 'react';
|
|
14
14
|
import { View, type GestureResponderEvent, type ViewProps } from 'react-native';
|
|
15
15
|
|
|
16
|
-
import { pushSignal } from '@goliapkg/sentori-core';
|
|
16
|
+
import { pushSignal, snapshotSignals } from '@goliapkg/sentori-core';
|
|
17
17
|
|
|
18
18
|
import { getConfig } from './config';
|
|
19
19
|
import { currentScreen } from './navigation';
|
|
20
20
|
import { RAGE_THRESHOLD, RAGE_WINDOW_MS, recordTap } from './rage-tap-detector';
|
|
21
|
+
import {
|
|
22
|
+
RESPONSE_WINDOW_MS,
|
|
23
|
+
SLUGGISH_MS,
|
|
24
|
+
classifyTap,
|
|
25
|
+
recordDeadTap,
|
|
26
|
+
recordSluggish,
|
|
27
|
+
} from './responsiveness-detector';
|
|
21
28
|
import { warnDetected } from './verbs';
|
|
22
29
|
|
|
23
30
|
export function RageTapCapture({
|
|
@@ -25,13 +32,50 @@ export function RageTapCapture({
|
|
|
25
32
|
...rest
|
|
26
33
|
}: ViewProps & { children?: React.ReactNode }): React.JSX.Element {
|
|
27
34
|
const recent = useRef<Map<number, number[]>>(new Map());
|
|
35
|
+
const deadBuckets = useRef<Map<number, number[]>>(new Map());
|
|
36
|
+
const sluggishWarns = useRef<Map<number, number>>(new Map());
|
|
28
37
|
|
|
29
38
|
const onTouchEnd = useCallback((e: GestureResponderEvent) => {
|
|
30
39
|
try {
|
|
31
40
|
const target = e.nativeEvent?.target;
|
|
32
41
|
if (typeof target !== 'number') return;
|
|
42
|
+
const tapAt = Date.now();
|
|
33
43
|
pushSignal('tap', { target });
|
|
34
|
-
|
|
44
|
+
|
|
45
|
+
// Responsiveness verdict lands after the window closes: the
|
|
46
|
+
// ring tells us whether the app reacted to this tap at all.
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
try {
|
|
49
|
+
const screen = currentScreen();
|
|
50
|
+
// Ring snapshots carry event-relative seconds (one decimal);
|
|
51
|
+
// rebase them onto the epoch for the classifier.
|
|
52
|
+
const nowMs = Date.now();
|
|
53
|
+
const times = snapshotSignals(nowMs)
|
|
54
|
+
.filter((s) => s.kind !== 'tap')
|
|
55
|
+
.map((s) => nowMs + s.t * 1000);
|
|
56
|
+
const outcome = classifyTap(tapAt, times);
|
|
57
|
+
if (outcome === 'dead' && recordDeadTap(deadBuckets.current, target, Date.now())) {
|
|
58
|
+
warnDetected(
|
|
59
|
+
'dead_button',
|
|
60
|
+
{ screen, element: String(target) },
|
|
61
|
+
{ windowMs: RESPONSE_WINDOW_MS },
|
|
62
|
+
);
|
|
63
|
+
} else if (
|
|
64
|
+
outcome === 'sluggish' &&
|
|
65
|
+
recordSluggish(sluggishWarns.current, target, Date.now())
|
|
66
|
+
) {
|
|
67
|
+
warnDetected(
|
|
68
|
+
'sluggish_button',
|
|
69
|
+
{ screen, element: String(target) },
|
|
70
|
+
{ thresholdMs: SLUGGISH_MS },
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
// detector bug must never surface
|
|
75
|
+
}
|
|
76
|
+
}, RESPONSE_WINDOW_MS + 50);
|
|
77
|
+
|
|
78
|
+
if (!recordTap(recent.current, target, tapAt)) return;
|
|
35
79
|
if (getConfig()?.detect.rageTap === false) return;
|
|
36
80
|
warnDetected(
|
|
37
81
|
'rage_tap',
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// B-type visual replay — a rolling ring of low-bitrate screenshots.
|
|
2
|
+
//
|
|
3
|
+
// OFF by default (privacy + the client-zero-cost rule): enable
|
|
4
|
+
// with `init({ replayScreens: true })`. One frame every 2.5 s at
|
|
5
|
+
// 360 px / q≈0.35 runs 10-20 KB, so the 60 s window a triage
|
|
6
|
+
// actually wants is ~24 frames and a few hundred KB — and those
|
|
7
|
+
// bytes only ever leave the device when an error/warn fires,
|
|
8
|
+
// stapled to that event as a `screens` attachment.
|
|
9
|
+
//
|
|
10
|
+
// Older native builds have no `captureReplayFrame`; the ring then
|
|
11
|
+
// simply stays empty (one warn) — wireframe replay still works.
|
|
12
|
+
|
|
13
|
+
import { logger } from '@goliapkg/sentori-core';
|
|
14
|
+
|
|
15
|
+
import { maskedNativeIds } from './mask';
|
|
16
|
+
import { captureNativeReplayFrame } from './native';
|
|
17
|
+
|
|
18
|
+
type CaptureFn = typeof captureNativeReplayFrame;
|
|
19
|
+
let _capture: CaptureFn = captureNativeReplayFrame;
|
|
20
|
+
|
|
21
|
+
/** Frame cadence. 2.5 s keeps the main-thread cost of a capture
|
|
22
|
+
* (~1-3 ms) far under the 1 % occupancy budget. */
|
|
23
|
+
const TICK_INTERVAL_MS = 2_500;
|
|
24
|
+
/** Long edge of a replay frame, px. Enough to read a screen's
|
|
25
|
+
* layout and large text; deliberately not enough to read a
|
|
26
|
+
* document over someone's shoulder. */
|
|
27
|
+
const FRAME_LONG_EDGE_PX = 360;
|
|
28
|
+
/** JPEG/WebP quality for replay frames. */
|
|
29
|
+
const FRAME_QUALITY = 0.35;
|
|
30
|
+
|
|
31
|
+
type ScreenFrame = { t: number; base64: string; mediaType: string };
|
|
32
|
+
|
|
33
|
+
let _ring: ScreenFrame[] = [];
|
|
34
|
+
let _capacity = 0;
|
|
35
|
+
let _timer: ReturnType<typeof setInterval> | null = null;
|
|
36
|
+
let _capturing = false;
|
|
37
|
+
|
|
38
|
+
/** Start the ring. `windowSeconds` is how far back the replay
|
|
39
|
+
* reaches when an event fires. */
|
|
40
|
+
export const startScreenReplay = (windowSeconds: number): void => {
|
|
41
|
+
if (_timer !== null || windowSeconds <= 0) return;
|
|
42
|
+
_capacity = Math.max(1, Math.ceil((windowSeconds * 1000) / TICK_INTERVAL_MS));
|
|
43
|
+
_timer = setInterval(() => {
|
|
44
|
+
void tick();
|
|
45
|
+
}, TICK_INTERVAL_MS);
|
|
46
|
+
logger.debug('replay-screens', `ring started: ${_capacity} slots / ${windowSeconds}s`);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const tick = async (): Promise<void> => {
|
|
50
|
+
// Never overlap captures: a slow frame skips a beat instead of
|
|
51
|
+
// queueing main-thread work.
|
|
52
|
+
if (_capturing) return;
|
|
53
|
+
_capturing = true;
|
|
54
|
+
try {
|
|
55
|
+
const frame = await _capture(maskedNativeIds(), FRAME_LONG_EDGE_PX, FRAME_QUALITY);
|
|
56
|
+
if (frame) {
|
|
57
|
+
_ring.push({ t: Date.now(), ...frame });
|
|
58
|
+
if (_ring.length > _capacity) _ring.splice(0, _ring.length - _capacity);
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
_capturing = false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Drain the ring into the wire form: NDJSON, one frame per line,
|
|
66
|
+
* `t` rewritten to seconds-before-now (negative, so the player
|
|
67
|
+
* reads "-42.5s → 0s"). Returns null when empty. The ring is NOT
|
|
68
|
+
* cleared — a second error two seconds later should still see
|
|
69
|
+
* the minute before it. */
|
|
70
|
+
export const drainScreenReplay = (): null | string => {
|
|
71
|
+
if (_ring.length === 0) return null;
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
return _ring
|
|
74
|
+
.map((f) =>
|
|
75
|
+
JSON.stringify({
|
|
76
|
+
t: Number(((f.t - now) / 1000).toFixed(1)),
|
|
77
|
+
mediaType: f.mediaType,
|
|
78
|
+
base64: f.base64,
|
|
79
|
+
}),
|
|
80
|
+
)
|
|
81
|
+
.join('\n');
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const __resetForTests = (): void => {
|
|
85
|
+
if (_timer !== null) clearInterval(_timer);
|
|
86
|
+
_timer = null;
|
|
87
|
+
_ring = [];
|
|
88
|
+
_capacity = 0;
|
|
89
|
+
_capturing = false;
|
|
90
|
+
_capture = captureNativeReplayFrame;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const __setCaptureForTests = (fn: CaptureFn): void => {
|
|
94
|
+
_capture = fn;
|
|
95
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// dead_button / sluggish_button — pure detection logic.
|
|
2
|
+
//
|
|
3
|
+
// A tap is judged by what the signal ring records after it: any
|
|
4
|
+
// non-tap signal (navigation, network, a trace point) inside the
|
|
5
|
+
// response window counts as the app reacting.
|
|
6
|
+
//
|
|
7
|
+
// - responsive: a reaction within SLUGGISH_MS.
|
|
8
|
+
// - sluggish: a reaction, but slower than SLUGGISH_MS.
|
|
9
|
+
// - dead: no reaction at all inside RESPONSE_WINDOW_MS.
|
|
10
|
+
//
|
|
11
|
+
// One dead tap is usually decoration (backgrounds, labels), so a
|
|
12
|
+
// dead_button warn needs DEAD_THRESHOLD dead taps on the SAME
|
|
13
|
+
// target inside DEAD_WINDOW_MS — a user repeatedly poking one
|
|
14
|
+
// unresponsive control, at a slower cadence than a rage tap.
|
|
15
|
+
// Sluggish warns are per-target cooldown-limited so one slow
|
|
16
|
+
// button files one issue, not one per tap.
|
|
17
|
+
|
|
18
|
+
export const RESPONSE_WINDOW_MS = 1_500;
|
|
19
|
+
export const SLUGGISH_MS = 1_000;
|
|
20
|
+
export const DEAD_THRESHOLD = 3;
|
|
21
|
+
export const DEAD_WINDOW_MS = 30_000;
|
|
22
|
+
export const SLUGGISH_COOLDOWN_MS = 60_000;
|
|
23
|
+
|
|
24
|
+
export type TapOutcome = 'dead' | 'responsive' | 'sluggish';
|
|
25
|
+
|
|
26
|
+
/** Judge one tap by the ring signals that followed it.
|
|
27
|
+
* `signalTimes` are the timestamps (ms) of every non-tap signal
|
|
28
|
+
* recorded after `tapAt`. */
|
|
29
|
+
export function classifyTap(tapAt: number, signalTimes: number[]): TapOutcome {
|
|
30
|
+
const first = signalTimes
|
|
31
|
+
.filter((t) => t > tapAt && t - tapAt <= RESPONSE_WINDOW_MS)
|
|
32
|
+
.sort((a, b) => a - b)[0];
|
|
33
|
+
if (first === undefined) return 'dead';
|
|
34
|
+
return first - tapAt > SLUGGISH_MS ? 'sluggish' : 'responsive';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Per-target dead-tap bookkeeping. Returns true when this dead tap
|
|
38
|
+
* crosses the warn threshold (and clears the bucket so the next
|
|
39
|
+
* warn needs a fresh run of dead taps). */
|
|
40
|
+
export function recordDeadTap(
|
|
41
|
+
buckets: Map<number, number[]>,
|
|
42
|
+
target: number,
|
|
43
|
+
now: number,
|
|
44
|
+
): boolean {
|
|
45
|
+
const fresh = (buckets.get(target) ?? []).filter((t) => now - t <= DEAD_WINDOW_MS);
|
|
46
|
+
fresh.push(now);
|
|
47
|
+
if (fresh.length >= DEAD_THRESHOLD) {
|
|
48
|
+
buckets.delete(target);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
buckets.set(target, fresh);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Per-target sluggish cooldown. Returns true when a warn should
|
|
56
|
+
* fire (and stamps the cooldown). */
|
|
57
|
+
export function recordSluggish(
|
|
58
|
+
lastWarnAt: Map<number, number>,
|
|
59
|
+
target: number,
|
|
60
|
+
now: number,
|
|
61
|
+
): boolean {
|
|
62
|
+
const last = lastWarnAt.get(target);
|
|
63
|
+
if (last !== undefined && now - last < SLUGGISH_COOLDOWN_MS) return false;
|
|
64
|
+
lastWarnAt.set(target, now);
|
|
65
|
+
return true;
|
|
66
|
+
}
|