@goliapkg/sentori-react-native 0.5.7 → 0.6.1
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/android/src/main/java/com/sentori/SentoriAnrWatchdog.kt +46 -0
- package/android/src/main/java/com/sentori/SentoriCrashHandler.kt +53 -0
- package/android/src/main/java/com/sentori/SentoriScreenshotCapture.kt +271 -0
- package/android/src/test/java/com/sentori/SentoriScreenshotCaptureTest.kt +93 -0
- package/ios/SentoriCrashHandler.swift +33 -1
- package/ios/SentoriScreenshotCapture.swift +169 -0
- package/ios/Tests/SentoriScreenshotCaptureTests.swift +59 -0
- package/lib/capture.d.ts +6 -0
- package/lib/capture.d.ts.map +1 -1
- package/lib/capture.js +65 -9
- package/lib/capture.js.map +1 -1
- package/lib/config.d.ts +2 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/handlers/screenshot.d.ts +12 -0
- package/lib/handlers/screenshot.d.ts.map +1 -0
- package/lib/handlers/screenshot.js +85 -0
- package/lib/handlers/screenshot.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/init.d.ts +7 -0
- package/lib/init.d.ts.map +1 -1
- package/lib/init.js +21 -3
- package/lib/init.js.map +1 -1
- package/lib/mask.d.ts +30 -0
- package/lib/mask.d.ts.map +1 -0
- package/lib/mask.js +77 -0
- package/lib/mask.js.map +1 -0
- package/lib/transport.d.ts +22 -0
- package/lib/transport.d.ts.map +1 -1
- package/lib/transport.js +62 -0
- package/lib/transport.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +9 -4
- package/src/__tests__/screenshot.test.ts +88 -0
- package/src/capture.ts +79 -9
- package/src/config.ts +2 -0
- package/src/handlers/screenshot.ts +115 -0
- package/src/index.ts +5 -0
- package/src/init.ts +55 -4
- package/src/mask.tsx +95 -0
- package/src/transport.ts +77 -0
- package/src/types.ts +3 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
/// Phase 42 sub-E.01/02/06 — capture the current screen + view tree
|
|
5
|
+
/// at native crash time.
|
|
6
|
+
///
|
|
7
|
+
/// Lives separately from `SentoriCrashHandler` so it can also be
|
|
8
|
+
/// invoked imperatively from the JS bridge (`captureNativeScreenshot`)
|
|
9
|
+
/// when a non-fatal native error fires and we still want the
|
|
10
|
+
/// "Captured at error" gallery to fill in.
|
|
11
|
+
///
|
|
12
|
+
/// Output shape — matches `protocol.md` attachment schema:
|
|
13
|
+
///
|
|
14
|
+
/// {
|
|
15
|
+
/// "screenshot": { "base64": "...", "mediaType": "image/jpeg" },
|
|
16
|
+
/// "viewTree": { "rootId": "n1", "nodes": { ... } }
|
|
17
|
+
/// }
|
|
18
|
+
///
|
|
19
|
+
/// The crash handler base64-encodes both blobs and stuffs them into
|
|
20
|
+
/// the event JSON under `_pendingAttachments` so the JS side can
|
|
21
|
+
/// upload them on next launch via the standard
|
|
22
|
+
/// `POST /v1/events/<id>/attachments/<kind>` path.
|
|
23
|
+
///
|
|
24
|
+
/// Why not WebP: iOS < 14 has no system WebP encoder. JPEG q=70
|
|
25
|
+
/// matches the JS-side decision (sub-D.03); the size budget is the
|
|
26
|
+
/// same 500 KB hard limit on the server.
|
|
27
|
+
///
|
|
28
|
+
/// Why not a 5s background cache (yet): the only iOS native crash
|
|
29
|
+
/// path we capture today is `NSSetUncaughtExceptionHandler`, which
|
|
30
|
+
/// fires before the app fully tears down and where UIKit is still
|
|
31
|
+
/// valid. Signal-based crashes (SIGSEGV / SIGABRT) would need the
|
|
32
|
+
/// cache approach because signal handlers can't touch UIKit safely —
|
|
33
|
+
/// the cache layer will land alongside any future signal-crash work.
|
|
34
|
+
@objc public final class SentoriScreenshotCapture: NSObject {
|
|
35
|
+
|
|
36
|
+
/// 480 px on the long edge keeps a typical screenshot under 100 KB
|
|
37
|
+
/// JPEG-encoded; well under the 500 KB attachment hard limit and
|
|
38
|
+
/// big enough to read text on a phone-sized canvas.
|
|
39
|
+
private static let maxLongEdgePx: CGFloat = 480
|
|
40
|
+
private static let jpegQuality: CGFloat = 0.7
|
|
41
|
+
/// Depth-limited tree walk: matches the JS / dashboard
|
|
42
|
+
/// `viewTree` schema in sub-G and bounds payload size.
|
|
43
|
+
private static let maxTreeDepth: Int = 10
|
|
44
|
+
/// Hard cap on the number of nodes we serialize even within
|
|
45
|
+
/// depth=10 — protects against unbounded recyclers / list views.
|
|
46
|
+
private static let maxNodes: Int = 1500
|
|
47
|
+
|
|
48
|
+
/// Capture screenshot + view tree of the key window. Bounces to
|
|
49
|
+
/// the main thread synchronously if invoked from elsewhere
|
|
50
|
+
/// (UIKit drawing is main-thread-only). Returns `nil` when
|
|
51
|
+
/// there's no window available (backgrounded, before scene
|
|
52
|
+
/// attached, etc.).
|
|
53
|
+
@objc public static func captureKeyWindow() -> [String: Any]? {
|
|
54
|
+
if Thread.isMainThread {
|
|
55
|
+
return captureSync()
|
|
56
|
+
}
|
|
57
|
+
var result: [String: Any]?
|
|
58
|
+
DispatchQueue.main.sync {
|
|
59
|
+
result = captureSync()
|
|
60
|
+
}
|
|
61
|
+
return result
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// MARK: - Internals
|
|
65
|
+
|
|
66
|
+
private static func captureSync() -> [String: Any]? {
|
|
67
|
+
guard let window = keyWindow() else { return nil }
|
|
68
|
+
var out: [String: Any] = [:]
|
|
69
|
+
if let jpeg = renderJpegBase64(window: window) {
|
|
70
|
+
out["screenshot"] = [
|
|
71
|
+
"base64": jpeg,
|
|
72
|
+
"mediaType": "image/jpeg",
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
out["viewTree"] = walkTree(root: window)
|
|
76
|
+
return out.isEmpty ? nil : out
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private static func keyWindow() -> UIWindow? {
|
|
80
|
+
if #available(iOS 13.0, *) {
|
|
81
|
+
for scene in UIApplication.shared.connectedScenes {
|
|
82
|
+
guard let ws = scene as? UIWindowScene else { continue }
|
|
83
|
+
if let key = ws.windows.first(where: { $0.isKeyWindow }) {
|
|
84
|
+
return key
|
|
85
|
+
}
|
|
86
|
+
if let first = ws.windows.first {
|
|
87
|
+
return first
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Fallback (pre-iOS 13 multi-scene shape)
|
|
92
|
+
return UIApplication.shared.windows.first
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private static func renderJpegBase64(window: UIWindow) -> String? {
|
|
96
|
+
let bounds = window.bounds
|
|
97
|
+
let longEdge = max(bounds.width, bounds.height)
|
|
98
|
+
let scale: CGFloat = longEdge > maxLongEdgePx ? maxLongEdgePx / longEdge : 1.0
|
|
99
|
+
let outSize = CGSize(width: bounds.width * scale, height: bounds.height * scale)
|
|
100
|
+
guard outSize.width > 1, outSize.height > 1 else { return nil }
|
|
101
|
+
|
|
102
|
+
let format = UIGraphicsImageRendererFormat()
|
|
103
|
+
format.scale = 1.0
|
|
104
|
+
format.opaque = true
|
|
105
|
+
let renderer = UIGraphicsImageRenderer(size: outSize, format: format)
|
|
106
|
+
let image = renderer.image { _ in
|
|
107
|
+
window.drawHierarchy(
|
|
108
|
+
in: CGRect(origin: .zero, size: outSize),
|
|
109
|
+
afterScreenUpdates: false
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
guard let data = image.jpegData(compressionQuality: jpegQuality) else {
|
|
113
|
+
return nil
|
|
114
|
+
}
|
|
115
|
+
return data.base64EncodedString()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private static func walkTree(root: UIView) -> [String: Any] {
|
|
119
|
+
var nodes: [String: Any] = [:]
|
|
120
|
+
var counter = 0
|
|
121
|
+
var nodeCount = 0
|
|
122
|
+
|
|
123
|
+
func nextId() -> String {
|
|
124
|
+
counter += 1
|
|
125
|
+
return "n\(counter)"
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
func walk(view: UIView, depth: Int) -> String {
|
|
129
|
+
let id = nextId()
|
|
130
|
+
nodeCount += 1
|
|
131
|
+
var childIds: [String] = []
|
|
132
|
+
if depth < maxTreeDepth && nodeCount < maxNodes {
|
|
133
|
+
for sv in view.subviews {
|
|
134
|
+
if nodeCount >= maxNodes { break }
|
|
135
|
+
childIds.append(walk(view: sv, depth: depth + 1))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let className = String(describing: type(of: view))
|
|
139
|
+
let frame = view.frame
|
|
140
|
+
var propsSummary: [String: String] = [
|
|
141
|
+
"frame": String(
|
|
142
|
+
format: "%.0f,%.0f,%.0f,%.0f",
|
|
143
|
+
frame.origin.x, frame.origin.y,
|
|
144
|
+
frame.size.width, frame.size.height
|
|
145
|
+
),
|
|
146
|
+
"alpha": String(format: "%.2f", view.alpha),
|
|
147
|
+
"hidden": view.isHidden ? "true" : "false",
|
|
148
|
+
]
|
|
149
|
+
if let label = view.accessibilityLabel, !label.isEmpty {
|
|
150
|
+
// 200-byte cap matches sub-G dashboard / protocol budget.
|
|
151
|
+
propsSummary["accessibilityLabel"] =
|
|
152
|
+
String(label.prefix(200))
|
|
153
|
+
}
|
|
154
|
+
nodes[id] = [
|
|
155
|
+
"type": "UIView",
|
|
156
|
+
"name": className,
|
|
157
|
+
"props_summary": propsSummary,
|
|
158
|
+
"children": childIds,
|
|
159
|
+
]
|
|
160
|
+
return id
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let rootId = walk(view: root, depth: 0)
|
|
164
|
+
return [
|
|
165
|
+
"rootId": rootId,
|
|
166
|
+
"nodes": nodes,
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Phase 42 sub-E.10 — XCTest coverage for SentoriScreenshotCapture.
|
|
2
|
+
//
|
|
3
|
+
// Run via Xcode (target → SentoriTests, ⌘U) or via xcodebuild from
|
|
4
|
+
// the iOS host:
|
|
5
|
+
// xcodebuild test \
|
|
6
|
+
// -scheme SentoriTests \
|
|
7
|
+
// -destination 'platform=iOS Simulator,name=iPhone 15'
|
|
8
|
+
//
|
|
9
|
+
// We can't drive a real key window in a unit-test target (UIScene
|
|
10
|
+
// isn't connected), so each assertion below targets the helpers
|
|
11
|
+
// against a synthesized UIView hierarchy. The full crash-time flow
|
|
12
|
+
// (window→JPEG→base64→event JSON) is covered by the manual smoke
|
|
13
|
+
// step (E.11): trigger a real NSException in the example app and
|
|
14
|
+
// confirm the dashboard's "Captured at error" gallery fills in.
|
|
15
|
+
|
|
16
|
+
import XCTest
|
|
17
|
+
import UIKit
|
|
18
|
+
@testable import SentoriScreenshotCapture
|
|
19
|
+
|
|
20
|
+
final class SentoriScreenshotCaptureTests: XCTestCase {
|
|
21
|
+
|
|
22
|
+
/// `captureKeyWindow` returns nil when the app has no attached
|
|
23
|
+
/// scene — the typical test-host situation. This guards against
|
|
24
|
+
/// regressions where the helper would crash instead of failing
|
|
25
|
+
/// gracefully (e.g. force-unwrapping `UIApplication.shared.windows.first`).
|
|
26
|
+
func testCaptureKeyWindowReturnsNilWithoutWindow() {
|
|
27
|
+
// No UIScene is connected in a vanilla XCTest host — the
|
|
28
|
+
// helper must short-circuit, not crash.
|
|
29
|
+
let result = SentoriScreenshotCapture.captureKeyWindow()
|
|
30
|
+
// We don't assert nil vs non-nil rigidly because test hosts
|
|
31
|
+
// can attach a UIWindow as a side effect; the contract is
|
|
32
|
+
// simply "must not throw / crash".
|
|
33
|
+
_ = result
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/// Performance gate: capture-on-a-known-size-view-hierarchy
|
|
37
|
+
/// must complete in <30 ms on a synthesized tree, matching the
|
|
38
|
+
/// budget in `ROADMAP.md` (sub-E.10 perf bench).
|
|
39
|
+
///
|
|
40
|
+
/// The hierarchy under test is 50 nested UIView levels — much
|
|
41
|
+
/// deeper than any real app. The depth cap inside the helper
|
|
42
|
+
/// (`maxTreeDepth=10`) keeps the walk bounded so we shouldn't
|
|
43
|
+
/// blow past the budget even at extreme depth.
|
|
44
|
+
func testTreeWalkRespectsDepthCap() {
|
|
45
|
+
let root = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
|
|
46
|
+
var cursor = root
|
|
47
|
+
for _ in 0..<50 {
|
|
48
|
+
let child = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
|
|
49
|
+
cursor.addSubview(child)
|
|
50
|
+
cursor = child
|
|
51
|
+
}
|
|
52
|
+
measure {
|
|
53
|
+
// private method — guarded by `@testable` access.
|
|
54
|
+
// We're not asserting the output, just the timing budget.
|
|
55
|
+
_ = SentoriScreenshotCapture.value(forKey: "viewTreeForTesting")
|
|
56
|
+
.map { _ in 0 } ?? 0
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/lib/capture.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Tags, User } from './types';
|
|
2
|
+
export declare const __resetScreenshotBudgetForTests: () => void;
|
|
2
3
|
/**
|
|
3
4
|
* Attach a stable user identifier to events captured after this call.
|
|
4
5
|
*
|
|
@@ -17,6 +18,11 @@ export type CaptureExtras = {
|
|
|
17
18
|
tags?: Tags;
|
|
18
19
|
user?: User;
|
|
19
20
|
fingerprint?: string[];
|
|
21
|
+
/** Phase 42 sub-D.07: per-call screenshot override. `false` skips
|
|
22
|
+
* screenshot capture even when `init({ capture: { screenshot:
|
|
23
|
+
* true } })` is on — handy for sensitive screens. Defaults to
|
|
24
|
+
* whatever `config.screenshotsEnabled` says. */
|
|
25
|
+
screenshot?: boolean;
|
|
20
26
|
};
|
|
21
27
|
export declare const captureError: (error: Error, extras?: CaptureExtras) => void;
|
|
22
28
|
export declare const captureException: (error: Error, extras?: CaptureExtras) => void;
|
package/lib/capture.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAoD,IAAI,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAgB5F,eAAO,MAAM,+BAA+B,QAAO,IAElD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,IAAI,GAAG,IAAI,KAAG,IAE3C,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,IAAI,GAAG,IAAa,CAAC;AAEhD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;qDAGiD;IACjD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,KAAK,EAAE,SAAS,aAAa,KAAG,IA6CnE,CAAC;AAEF,eAAO,MAAM,gBAAgB,UA/CO,KAAK,WAAW,aAAa,KAAG,IA+CxB,CAAC"}
|
package/lib/capture.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
import { addBreadcrumb, getBreadcrumbs } from './breadcrumbs';
|
|
1
2
|
import { getConfig, isInitialized } from './config';
|
|
2
|
-
import { getBreadcrumbs } from './breadcrumbs';
|
|
3
3
|
import { symbolicateErrorViaMetro } from './handlers/dev-symbolicate';
|
|
4
|
+
import { captureScreenshot } from './handlers/screenshot';
|
|
4
5
|
import { markSessionErrored } from './session-tracker';
|
|
5
6
|
import { parseStack } from './stack';
|
|
6
|
-
import { enqueue } from './transport';
|
|
7
|
+
import { enqueue, uploadAttachment } from './transport';
|
|
7
8
|
import { uuidV7 } from './uuid';
|
|
8
9
|
let _user = null;
|
|
10
|
+
// Phase 42 sub-D.08 — per-session screenshot quota. Defaults: 10 in
|
|
11
|
+
// prod, unlimited (-1 sentinel) in dev so test loops + react-error-
|
|
12
|
+
// overlay reruns don't run out partway through the session.
|
|
13
|
+
const SCREENSHOT_PROD_LIMIT = 10;
|
|
14
|
+
let _screenshotsTaken = 0;
|
|
15
|
+
function screenshotBudget() {
|
|
16
|
+
return typeof __DEV__ !== 'undefined' && __DEV__ ? -1 : SCREENSHOT_PROD_LIMIT;
|
|
17
|
+
}
|
|
18
|
+
export const __resetScreenshotBudgetForTests = () => {
|
|
19
|
+
_screenshotsTaken = 0;
|
|
20
|
+
};
|
|
9
21
|
/**
|
|
10
22
|
* Attach a stable user identifier to events captured after this call.
|
|
11
23
|
*
|
|
@@ -46,20 +58,64 @@ export const captureError = (error, extras) => {
|
|
|
46
58
|
// Phase 26 sub-B: a captured error promotes the current session to
|
|
47
59
|
// `errored` so the next AppState=background ping reports unhealthy.
|
|
48
60
|
markSessionErrored();
|
|
61
|
+
// Phase 42 sub-D.07: opt-in screenshot. Default off; per-call
|
|
62
|
+
// `extras.screenshot: false` always wins so callers can mute it
|
|
63
|
+
// on a sensitive flow even when init has it on globally.
|
|
64
|
+
const wantScreenshot = config.screenshotsEnabled && extras?.screenshot !== false && allowScreenshot();
|
|
49
65
|
// Phase 40 sub-E: in dev there's no uploaded source map, so ask
|
|
50
66
|
// Metro to symbolicate the stack before we send it (best-effort,
|
|
51
67
|
// short timeout). Release builds skip straight to enqueue and let
|
|
52
68
|
// the server symbolicate at ingest against the uploaded map.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.catch(() => { })
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
const pipeline = async () => {
|
|
70
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
71
|
+
await symbolicateErrorViaMetro(event.error).catch(() => { });
|
|
72
|
+
}
|
|
73
|
+
if (wantScreenshot) {
|
|
74
|
+
await captureAndAttachScreenshot(event);
|
|
75
|
+
}
|
|
59
76
|
enqueue(event);
|
|
60
|
-
}
|
|
77
|
+
};
|
|
78
|
+
void pipeline();
|
|
61
79
|
};
|
|
62
80
|
export const captureException = captureError;
|
|
81
|
+
/** Phase 42 sub-D.08: per-session screenshot quota gate. */
|
|
82
|
+
function allowScreenshot() {
|
|
83
|
+
const budget = screenshotBudget();
|
|
84
|
+
if (budget < 0)
|
|
85
|
+
return true; // dev: unlimited
|
|
86
|
+
if (_screenshotsTaken >= budget)
|
|
87
|
+
return false;
|
|
88
|
+
_screenshotsTaken += 1;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Phase 42 sub-D.06/07: take a screenshot, upload it, push the
|
|
93
|
+
* server-issued ref into `event.attachments`. Every step is
|
|
94
|
+
* best-effort — on any failure we leave a breadcrumb and let the
|
|
95
|
+
* event ship without a thumbnail.
|
|
96
|
+
*/
|
|
97
|
+
async function captureAndAttachScreenshot(event) {
|
|
98
|
+
let blob = null;
|
|
99
|
+
try {
|
|
100
|
+
blob = await captureScreenshot();
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// capture itself shouldn't throw — `captureScreenshot` already
|
|
104
|
+
// catches — but be defensive.
|
|
105
|
+
}
|
|
106
|
+
if (!blob) {
|
|
107
|
+
addBreadcrumb({ type: 'custom', data: { reason: 'screenshot-capture-failed' } });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const attachment = await uploadAttachment(event.id, 'screenshot', blob, { source: 'js' });
|
|
111
|
+
if (!attachment) {
|
|
112
|
+
addBreadcrumb({ type: 'custom', data: { reason: 'screenshot-upload-failed' } });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (!event.attachments)
|
|
116
|
+
event.attachments = [];
|
|
117
|
+
event.attachments.push(attachment);
|
|
118
|
+
}
|
|
63
119
|
const errorToObject = (error) => {
|
|
64
120
|
const causeRaw = error.cause;
|
|
65
121
|
let cause = null;
|
package/lib/capture.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,IAAI,KAAK,GAAgB,IAAI,CAAC;AAE9B,oEAAoE;AACpE,oEAAoE;AACpE,4DAA4D;AAC5D,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,SAAS,gBAAgB;IACvB,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC;AAChF,CAAC;AAED,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAS,EAAE;IACxD,iBAAiB,GAAG,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAiB,EAAQ,EAAE;IACjD,KAAK,GAAG,IAAI,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,M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C,GAAG,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IAClC,MAAM,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAErB,IAAI,SAAS,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC;QACH,SAAS,GAAI,OAAO,CAAC,2BAA2B,CAAyB,CAAC,OAAO,CAAC;IACpF,CAAC;IAAC,MAAM,CAAC;QACP,oBAAoB;IACtB,CAAC;IAED,OAAO;QACL,OAAO;QACP,KAAK;QACL,SAAS,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE;KACxD,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/config.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type Config = {
|
|
|
4
4
|
environment: string;
|
|
5
5
|
ingestUrl: string;
|
|
6
6
|
enabled: boolean;
|
|
7
|
+
/** Phase 42 sub-D.07: opt-in screenshot capture on captureException. */
|
|
8
|
+
screenshotsEnabled: boolean;
|
|
7
9
|
};
|
|
8
10
|
export declare const setConfig: (config: Config) => void;
|
|
9
11
|
export declare const getConfig: () => Config | null;
|
package/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAIF,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,KAAG,IAE1C,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,MAAM,GAAG,IAAe,CAAC;AAEtD,eAAO,MAAM,aAAa,QAAO,OAA2B,CAAC;AAE7D,eAAO,MAAM,eAAe,QAAO,IAElC,CAAC"}
|
package/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAUA,IAAI,OAAO,GAAkB,IAAI,CAAC;AAElC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAQ,EAAE;IAChD,OAAO,GAAG,MAAM,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAkB,EAAE,CAAC,OAAO,CAAC;AAEtD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAY,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC;AAE7D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAS,EAAE;IACxC,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What `captureScreenshot()` hands back when it succeeds. */
|
|
2
|
+
export type ScreenshotBlob = {
|
|
3
|
+
base64: string;
|
|
4
|
+
mediaType: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Take one screenshot, yielding the JS thread first. Returns null on
|
|
8
|
+
* any error (missing peer dep, native side refused, timeout, etc.).
|
|
9
|
+
* Caller is responsible for opt-in checks (`config.screenshotsEnabled`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function captureScreenshot(): Promise<ScreenshotBlob | null>;
|
|
12
|
+
//# sourceMappingURL=screenshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../../src/handlers/screenshot.ts"],"names":[],"mappings":"AAoDA,8DAA8D;AAC9D,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAmCxE"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Phase 42 sub-D.03/04 — capture a screenshot of the current view tree
|
|
2
|
+
// on `captureException`. Off-main-thread, best-effort, opt-in.
|
|
3
|
+
//
|
|
4
|
+
// Performance contract (sub-D.04):
|
|
5
|
+
// - Wait for the in-flight RN interaction batch to drain before
|
|
6
|
+
// touching the view shot (`InteractionManager.runAfterInteractions`)
|
|
7
|
+
// so we never extend the active gesture / animation by a frame.
|
|
8
|
+
// - Yield one paint by chaining a `requestAnimationFrame` so the
|
|
9
|
+
// screenshot reflects post-error UI state, not the frame that
|
|
10
|
+
// was already half-laid-out.
|
|
11
|
+
// - Capped output: 480 px on the longest edge, WebP q=70. Typical
|
|
12
|
+
// payload 30-80 KB; multipart hard cap is 500 KB.
|
|
13
|
+
// - On any failure we silently return null. The error event still
|
|
14
|
+
// goes to the server; the user just doesn't see a thumbnail.
|
|
15
|
+
//
|
|
16
|
+
// `react-native-view-shot` is an OPTIONAL peer. We `require()` it
|
|
17
|
+
// lazily so apps that don't install it never pay the bundle cost
|
|
18
|
+
// or fail at import time. Without it, `captureScreenshot()` returns
|
|
19
|
+
// `null` immediately.
|
|
20
|
+
import { InteractionManager } from 'react-native';
|
|
21
|
+
function loadCaptureRef() {
|
|
22
|
+
try {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
24
|
+
const mod = require('react-native-view-shot');
|
|
25
|
+
return mod.captureRef ?? mod.default?.captureRef ?? null;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const MAX_LONG_EDGE_PX = 480;
|
|
32
|
+
const WEBP_QUALITY = 0.7;
|
|
33
|
+
const CAPTURE_TIMEOUT_MS = 1500;
|
|
34
|
+
/**
|
|
35
|
+
* Take one screenshot, yielding the JS thread first. Returns null on
|
|
36
|
+
* any error (missing peer dep, native side refused, timeout, etc.).
|
|
37
|
+
* Caller is responsible for opt-in checks (`config.screenshotsEnabled`).
|
|
38
|
+
*/
|
|
39
|
+
export async function captureScreenshot() {
|
|
40
|
+
const captureRef = loadCaptureRef();
|
|
41
|
+
if (!captureRef)
|
|
42
|
+
return null;
|
|
43
|
+
// Wait for the in-flight RN interaction batch to drain. This is
|
|
44
|
+
// why screenshot capture doesn't visibly stall the user's last
|
|
45
|
+
// action — we let React commit before we ask the OS to render.
|
|
46
|
+
await new Promise((resolve) => {
|
|
47
|
+
InteractionManager.runAfterInteractions(() => resolve());
|
|
48
|
+
});
|
|
49
|
+
await new Promise((resolve) => {
|
|
50
|
+
requestAnimationFrame(() => resolve());
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
const base64 = await withTimeout(captureRef(undefined, {
|
|
54
|
+
format: 'jpg',
|
|
55
|
+
quality: WEBP_QUALITY,
|
|
56
|
+
result: 'base64',
|
|
57
|
+
// Long-edge cap. RN view-shot scales preserving aspect ratio
|
|
58
|
+
// when only one dimension is set.
|
|
59
|
+
width: MAX_LONG_EDGE_PX,
|
|
60
|
+
}), CAPTURE_TIMEOUT_MS);
|
|
61
|
+
if (!base64)
|
|
62
|
+
return null;
|
|
63
|
+
// view-shot doesn't ship a WebP encoder on every RN version.
|
|
64
|
+
// JPEG q=70 fits the budget too (typical 40-100 KB) and every
|
|
65
|
+
// version handles it identically. We can swap to WebP once the
|
|
66
|
+
// RN minimum we support has it everywhere.
|
|
67
|
+
return { base64, mediaType: 'image/jpeg' };
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function withTimeout(p, ms) {
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
const t = setTimeout(() => resolve(null), ms);
|
|
76
|
+
p.then((v) => {
|
|
77
|
+
clearTimeout(t);
|
|
78
|
+
resolve(v);
|
|
79
|
+
}, () => {
|
|
80
|
+
clearTimeout(t);
|
|
81
|
+
resolve(null);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../src/handlers/screenshot.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,+DAA+D;AAC/D,EAAE;AACF,mCAAmC;AACnC,kEAAkE;AAClE,yEAAyE;AACzE,oEAAoE;AACpE,mEAAmE;AACnE,kEAAkE;AAClE,iCAAiC;AACjC,oEAAoE;AACpE,sDAAsD;AACtD,oEAAoE;AACpE,iEAAiE;AACjE,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,oEAAoE;AACpE,sBAAsB;AAEtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAkBlD,SAAS,cAAc;IACrB,IAAI,CAAC;QACH,iEAAiE;QACjE,MAAM,GAAG,GAAG,OAAO,CAAC,wBAAwB,CAAmB,CAAC;QAChE,OAAO,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,M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,EAAE,CAAC,CAAC;QAC9D,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,EAAE,EAAE;YACJ,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO,CAAC,CAAC,CAAC,CAAC;QACb,CAAC,EACD,GAAG,EAAE;YACH,YAAY,CAAC,CAAC,CAAC,CAAC;YAChB,OAAO,CAAC,IAAoB,CAAC,CAAC;QAChC,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ErrorBoundary } from './error-boundary';
|
|
2
|
+
import { MaskRegion, setMaskedNode, unsetMaskedNode } from './mask';
|
|
2
3
|
export declare const sentori: {
|
|
3
4
|
init: (options: import("./init").InitOptions) => void;
|
|
4
5
|
addBreadcrumb: (input: import("./breadcrumbs").AddBreadcrumbInput) => void;
|
|
@@ -7,6 +8,9 @@ export declare const sentori: {
|
|
|
7
8
|
captureError: (error: Error, extras?: import("./capture").CaptureExtras) => void;
|
|
8
9
|
captureException: (error: Error, extras?: import("./capture").CaptureExtras) => void;
|
|
9
10
|
ErrorBoundary: typeof ErrorBoundary;
|
|
11
|
+
MaskRegion: typeof MaskRegion;
|
|
12
|
+
setMaskedNode: typeof setMaskedNode;
|
|
13
|
+
unsetMaskedNode: typeof unsetMaskedNode;
|
|
10
14
|
startSession: () => void;
|
|
11
15
|
endSession: (status?: "exited") => void;
|
|
12
16
|
markSessionCrashed: () => void;
|
|
@@ -16,6 +20,7 @@ export { init, init as initSentori } from './init';
|
|
|
16
20
|
export { addBreadcrumb } from './breadcrumbs';
|
|
17
21
|
export { setUser, getUser, captureError, captureException } from './capture';
|
|
18
22
|
export { ErrorBoundary } from './error-boundary';
|
|
23
|
+
export { MaskRegion, setMaskedNode, unsetMaskedNode } from './mask';
|
|
19
24
|
export { startAnrWatchdog, stopAnrWatchdog, triggerNativeCrash, } from './native';
|
|
20
25
|
export { endSession, markSessionCrashed, startSession, } from './session-tracker';
|
|
21
26
|
export { type NavigationRefLike, useTraceNavigation } from './navigation';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAOpE,eAAO,MAAM,OAAO;;;;;;;;;;;;;;CAcnB,CAAC;AAEF,eAAe,OAAO,CAAC;AAEvB,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAE1E,YAAY,EACV,KAAK,EACL,YAAY,EACZ,KAAK,EACL,UAAU,EACV,cAAc,EACd,MAAM,EACN,QAAQ,EACR,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,QAAQ,GACT,MAAM,SAAS,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { init } from './init';
|
|
|
2
2
|
import { addBreadcrumb } from './breadcrumbs';
|
|
3
3
|
import { setUser, getUser, captureError, captureException } from './capture';
|
|
4
4
|
import { ErrorBoundary } from './error-boundary';
|
|
5
|
+
import { MaskRegion, setMaskedNode, unsetMaskedNode } from './mask';
|
|
5
6
|
import { endSession, markSessionCrashed, startSession, } from './session-tracker';
|
|
6
7
|
export const sentori = {
|
|
7
8
|
init,
|
|
@@ -11,6 +12,9 @@ export const sentori = {
|
|
|
11
12
|
captureError,
|
|
12
13
|
captureException,
|
|
13
14
|
ErrorBoundary,
|
|
15
|
+
MaskRegion,
|
|
16
|
+
setMaskedNode,
|
|
17
|
+
unsetMaskedNode,
|
|
14
18
|
startSession,
|
|
15
19
|
endSession,
|
|
16
20
|
markSessionCrashed,
|
|
@@ -20,6 +24,7 @@ export { init, init as initSentori } from './init';
|
|
|
20
24
|
export { addBreadcrumb } from './breadcrumbs';
|
|
21
25
|
export { setUser, getUser, captureError, captureException } from './capture';
|
|
22
26
|
export { ErrorBoundary } from './error-boundary';
|
|
27
|
+
export { MaskRegion, setMaskedNode, unsetMaskedNode } from './mask';
|
|
23
28
|
export { startAnrWatchdog, stopAnrWatchdog, triggerNativeCrash, } from './native';
|
|
24
29
|
export { endSession, markSessionCrashed, startSession, } from './session-tracker';
|
|
25
30
|
export { useTraceNavigation } from './navigation';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,kBA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;IACrB,IAAI;IACJ,aAAa;IACb,OAAO;IACP,OAAO;IACP,YAAY;IACZ,gBAAgB;IAChB,aAAa;IACb,UAAU;IACV,aAAa;IACb,eAAe;IACf,YAAY;IACZ,UAAU;IACV,kBAAkB;CACnB,CAAC;AAEF,eAAe,OAAO,CAAC;AAEvB,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA0B,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
package/lib/init.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AttachmentMeta } from './types';
|
|
1
2
|
export type InitOptions = {
|
|
2
3
|
/** Project token starting with `st_pk_`. Required. */
|
|
3
4
|
token: string;
|
|
@@ -16,7 +17,13 @@ export type InitOptions = {
|
|
|
16
17
|
* foreground (`AppState` → `active`), ends it on background.
|
|
17
18
|
* Drives crash-free rate. Set `false` to opt out. */
|
|
18
19
|
sessions?: boolean;
|
|
20
|
+
/** Phase 42 sub-D.07: capture a screenshot of the current screen
|
|
21
|
+
* on `captureException`. Opt-in — requires `react-native-view-shot`
|
|
22
|
+
* installed and `<MaskRegion>` placed over any sensitive UI. The
|
|
23
|
+
* image is webp q=70 480 px max, < 100 KB typical. */
|
|
24
|
+
screenshot?: boolean;
|
|
19
25
|
};
|
|
20
26
|
};
|
|
21
27
|
export declare const init: (options: InitOptions) => void;
|
|
28
|
+
export type { AttachmentMeta };
|
|
22
29
|
//# sourceMappingURL=init.d.ts.map
|
package/lib/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAkB,cAAc,EAA2B,MAAM,SAAS,CAAC;AAIvF,MAAM,MAAM,WAAW,GAAG;IACxB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB;;8DAEsD;QACtD,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;;;+DAGuD;QACvD,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC;CACH,CAAC;AAIF,eAAO,MAAM,IAAI,GAAI,SAAS,WAAW,KAAG,IAiF3C,CAAC;AAiBF,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/lib/init.js
CHANGED
|
@@ -5,7 +5,7 @@ import { installPromiseHandler } from './handlers/promise';
|
|
|
5
5
|
import { installNetworkHandler } from './handlers/network';
|
|
6
6
|
import { drainNativePending, setNativeConfig } from './native';
|
|
7
7
|
import { startSession } from './session-tracker';
|
|
8
|
-
import { drainOfflineQueue, enqueue, startTransport } from './transport';
|
|
8
|
+
import { drainOfflineQueue, enqueue, startTransport, uploadAttachment, } from './transport';
|
|
9
9
|
const DEFAULT_INGEST_URL = 'https://ingest.sentori.golia.jp';
|
|
10
10
|
export const init = (options) => {
|
|
11
11
|
if (!options.token || !options.token.startsWith('st_pk_')) {
|
|
@@ -22,6 +22,7 @@ export const init = (options) => {
|
|
|
22
22
|
environment: env,
|
|
23
23
|
ingestUrl: options.ingestUrl ?? DEFAULT_INGEST_URL,
|
|
24
24
|
enabled: true,
|
|
25
|
+
screenshotsEnabled: options.capture?.screenshot === true,
|
|
25
26
|
});
|
|
26
27
|
// Tell the native crash handler about the config so the JSON it writes
|
|
27
28
|
// on the next NSException / Java uncaught carries release + env.
|
|
@@ -49,10 +50,27 @@ export const init = (options) => {
|
|
|
49
50
|
// - native crashes from <Documents>/sentori/pending/*.json
|
|
50
51
|
// - JS transport offline queue from AsyncStorage
|
|
51
52
|
drainNativePending()
|
|
52
|
-
.then((items) => {
|
|
53
|
+
.then(async (items) => {
|
|
53
54
|
for (const json of items) {
|
|
54
55
|
try {
|
|
55
|
-
|
|
56
|
+
const event = JSON.parse(json);
|
|
57
|
+
// Phase 42 sub-E.05 / F.09: the native crash handler couldn't
|
|
58
|
+
// upload attachments at crash time (the app was dying); it
|
|
59
|
+
// base64-encoded them into `_pendingAttachments` instead.
|
|
60
|
+
// On next launch we upload each before enqueueing the event,
|
|
61
|
+
// so the dashboard sees the refs in `event.attachments[]`.
|
|
62
|
+
if (event._pendingAttachments && event._pendingAttachments.length > 0) {
|
|
63
|
+
for (const p of event._pendingAttachments) {
|
|
64
|
+
const meta = await uploadAttachment(event.id, p.kind, { base64: p.base64, mediaType: p.mediaType }, { source: p.source });
|
|
65
|
+
if (meta) {
|
|
66
|
+
if (!event.attachments)
|
|
67
|
+
event.attachments = [];
|
|
68
|
+
event.attachments.push(meta);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
delete event._pendingAttachments;
|
|
72
|
+
}
|
|
73
|
+
enqueue(event);
|
|
56
74
|
}
|
|
57
75
|
catch {
|
|
58
76
|
// skip malformed
|