@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.bugsee.library.Bugsee;
|
|
7
|
+
import com.bugsee.library.contracts.common.Callback1;
|
|
8
|
+
import com.bugsee.library.contracts.exchange.EventFilter;
|
|
9
|
+
import com.bugsee.library.contracts.exchange.NetworkEvent;
|
|
10
|
+
import com.bugsee.library.contracts.options.Options;
|
|
11
|
+
import com.bugsee.library.contracts.options.OptionsContainer;
|
|
12
|
+
|
|
13
|
+
import org.json.JSONException;
|
|
14
|
+
import org.json.JSONObject;
|
|
15
|
+
|
|
16
|
+
import java.util.ArrayList;
|
|
17
|
+
import java.util.HashMap;
|
|
18
|
+
import java.util.Iterator;
|
|
19
|
+
import java.util.List;
|
|
20
|
+
import java.util.Map;
|
|
21
|
+
import java.util.Objects;
|
|
22
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
23
|
+
import java.util.concurrent.ScheduledFuture;
|
|
24
|
+
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
25
|
+
import java.util.concurrent.TimeUnit;
|
|
26
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
27
|
+
import java.util.concurrent.atomic.AtomicLong;
|
|
28
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
29
|
+
import java.util.function.BooleanSupplier;
|
|
30
|
+
import java.util.function.Consumer;
|
|
31
|
+
import java.util.function.Supplier;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The app's network filter, as a round trip into JS.
|
|
35
|
+
*
|
|
36
|
+
* <p>Registered with {@link Bugsee#setNetworkEventFilter}. {@link #filter}
|
|
37
|
+
* returns without waiting. The SDK's {@code FilterCallbackWrapper} is a pooled
|
|
38
|
+
* {@link Callback1}. Its 10s recycle is posted before the filter is entered,
|
|
39
|
+
* so a forget scheduled at that same delay fires after the entry is back in
|
|
40
|
+
* the pool. This bridge forgets the pending request at {@link #BORROW_MS},
|
|
41
|
+
* strictly earlier, and does not call the callback: a later reply is a
|
|
42
|
+
* no-op, and it does not pass the original event through. A reply after
|
|
43
|
+
* {@link NetworkEvent#getUrl()} (or {@link NetworkEvent#getId()}) has changed
|
|
44
|
+
* returns without writing and without {@code callback.run}.
|
|
45
|
+
*/
|
|
46
|
+
final class NetworkFilterBridge {
|
|
47
|
+
|
|
48
|
+
/** What the module implements to emit {@code onNetworkFilterRequest}. */
|
|
49
|
+
interface Sink {
|
|
50
|
+
void onNetworkFilterRequest(@NonNull String requestId, @NonNull String eventJson);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Arms the moment a pending request is forgotten. Injectable so tests control time. */
|
|
54
|
+
interface Cancellable {
|
|
55
|
+
void cancel();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Arms a request's deadline. Injectable so tests control time. */
|
|
59
|
+
interface Scheduler {
|
|
60
|
+
@NonNull
|
|
61
|
+
Cancellable schedule(@NonNull Runnable task, long delayMs);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Strictly under {@code BugseeCaptureDataProviderNetwork.FILTER_CALLBACK_TIMEOUT_MS}
|
|
66
|
+
* (10s). That timer is already running when the filter is entered, so an
|
|
67
|
+
* equal delay forgets the pending after the entry has been recycled. A
|
|
68
|
+
* reused wrapper whose url text is unchanged would then still look
|
|
69
|
+
* borrowed, and a reply would write onto whatever event owns it.
|
|
70
|
+
* Forgetting here only removes the pending; it does not pass the event
|
|
71
|
+
* through.
|
|
72
|
+
*/
|
|
73
|
+
static final long BORROW_MS = 9_000L;
|
|
74
|
+
|
|
75
|
+
private static final class Pending {
|
|
76
|
+
@NonNull final String id;
|
|
77
|
+
@NonNull final NetworkEvent event;
|
|
78
|
+
@Nullable final String originalId;
|
|
79
|
+
@Nullable final String originalUrl;
|
|
80
|
+
@NonNull final Callback1<NetworkEvent> callback;
|
|
81
|
+
@NonNull final Sink owner;
|
|
82
|
+
@Nullable Cancellable deadline;
|
|
83
|
+
|
|
84
|
+
Pending(
|
|
85
|
+
@NonNull final String id,
|
|
86
|
+
@NonNull final NetworkEvent event,
|
|
87
|
+
@Nullable final String originalId,
|
|
88
|
+
@Nullable final String originalUrl,
|
|
89
|
+
@NonNull final Callback1<NetworkEvent> callback,
|
|
90
|
+
@NonNull final Sink owner
|
|
91
|
+
) {
|
|
92
|
+
this.id = id;
|
|
93
|
+
this.event = event;
|
|
94
|
+
this.originalId = originalId;
|
|
95
|
+
this.originalUrl = originalUrl;
|
|
96
|
+
this.callback = callback;
|
|
97
|
+
this.owner = owner;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static final NetworkFilterBridge SHARED = new NetworkFilterBridge();
|
|
102
|
+
|
|
103
|
+
@NonNull
|
|
104
|
+
static NetworkFilterBridge shared() {
|
|
105
|
+
return SHARED;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private final Scheduler scheduler;
|
|
109
|
+
private final BooleanSupplier defaultSanitizer;
|
|
110
|
+
private final AtomicReference<Sink> sink = new AtomicReference<>();
|
|
111
|
+
private final ConcurrentHashMap<String, Pending> pending = new ConcurrentHashMap<>();
|
|
112
|
+
private final AtomicLong ids = new AtomicLong();
|
|
113
|
+
private final AtomicBoolean installed = new AtomicBoolean();
|
|
114
|
+
|
|
115
|
+
/** Production: one daemon thread forgets pending requests at {@link #BORROW_MS}. */
|
|
116
|
+
private NetworkFilterBridge() {
|
|
117
|
+
this(new DaemonScheduler(), NetworkFilterBridge::readDefaultSanitizerOption);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Tests pass a scheduler they fire themselves, and whether
|
|
122
|
+
* {@link Options#CaptureNetworkUseDefaultSanitizer} is on. The production
|
|
123
|
+
* bridge reads that option; a JVM test cannot, because
|
|
124
|
+
* {@link Bugsee#getLaunchOptions()} needs an Android looper.
|
|
125
|
+
*/
|
|
126
|
+
NetworkFilterBridge(@NonNull final Scheduler scheduler, @NonNull final BooleanSupplier defaultSanitizer) {
|
|
127
|
+
this.scheduler = scheduler;
|
|
128
|
+
this.defaultSanitizer = defaultSanitizer;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private final EventFilter<NetworkEvent> filter = new EventFilter<NetworkEvent>() {
|
|
132
|
+
@Override
|
|
133
|
+
public void filter(
|
|
134
|
+
@NonNull final NetworkEvent event,
|
|
135
|
+
@NonNull final Callback1<NetworkEvent> callback
|
|
136
|
+
) {
|
|
137
|
+
try {
|
|
138
|
+
ask(event, callback);
|
|
139
|
+
} catch (final Throwable e) {
|
|
140
|
+
drop(callback);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
void attach(@NonNull final Sink next) {
|
|
146
|
+
sink.set(next);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Drops every request this sink was asked, while the entry is still the
|
|
151
|
+
* SDK's live borrow. After the entry has been recycled, the pending is
|
|
152
|
+
* forgotten and the callback is not touched.
|
|
153
|
+
*/
|
|
154
|
+
void detach(@NonNull final Sink current) {
|
|
155
|
+
sink.compareAndSet(current, null);
|
|
156
|
+
final List<Pending> owned = new ArrayList<>();
|
|
157
|
+
for (final Pending item : pending.values()) {
|
|
158
|
+
if (item.owner == current && pending.remove(item.id, item)) {
|
|
159
|
+
owned.add(item);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (final Pending item : owned) {
|
|
163
|
+
cancel(item.deadline);
|
|
164
|
+
if (stillBorrowed(item)) {
|
|
165
|
+
drop(item.callback);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Installs the filter, or removes it. A second {@code true} is a no-op. */
|
|
171
|
+
void setEnabled(final boolean enabled) {
|
|
172
|
+
if (enabled) {
|
|
173
|
+
if (installed.compareAndSet(false, true)) {
|
|
174
|
+
Bugsee.setNetworkEventFilter(filter);
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (installed.compareAndSet(true, false)) {
|
|
179
|
+
Bugsee.setNetworkEventFilter(null);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Applies JS's answer. {@code null} drops the event, while the entry is
|
|
185
|
+
* still the one the SDK lent us. A JSON object may replace {@code url},
|
|
186
|
+
* {@code body}, {@code headers}, {@code errorDescription},
|
|
187
|
+
* {@code errorShortMessage} and {@code statusText}; the same event is
|
|
188
|
+
* returned, so the timestamp and the stage stay. A field the entry
|
|
189
|
+
* ignores is a drop rather than an unredacted keep.
|
|
190
|
+
*
|
|
191
|
+
* <p>If {@code getId()} or {@code getUrl()} is no longer the original,
|
|
192
|
+
* the pooled entry has been recycled. This returns without writing and
|
|
193
|
+
* without {@code callback.run}.
|
|
194
|
+
*/
|
|
195
|
+
void reply(@NonNull final String requestId, @Nullable final String eventJson) {
|
|
196
|
+
final Pending item = pending.remove(requestId);
|
|
197
|
+
if (item == null) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
cancel(item.deadline);
|
|
201
|
+
if (!stillBorrowed(item)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (eventJson == null) {
|
|
205
|
+
drop(item.callback);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
if (!apply(item.event, eventJson)) {
|
|
210
|
+
drop(item.callback);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
} catch (final Throwable e) {
|
|
214
|
+
drop(item.callback);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
item.callback.run(item.event);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
void ask(
|
|
221
|
+
@NonNull final NetworkEvent event,
|
|
222
|
+
@NonNull final Callback1<NetworkEvent> callback
|
|
223
|
+
) {
|
|
224
|
+
// setNetworkEventFilter skips DefaultNetworkDataSanitizer. The
|
|
225
|
+
// capture provider runs it only when no filter is installed, and
|
|
226
|
+
// only when CaptureNetworkUseDefaultSanitizer is on (default true).
|
|
227
|
+
// Sanitize before the snapshot and before the url is remembered, so
|
|
228
|
+
// stillBorrowed compares the url the callback actually saw.
|
|
229
|
+
try {
|
|
230
|
+
if (defaultSanitizer.getAsBoolean()) {
|
|
231
|
+
Bugsee.getDefaultNetworkSanitizer().sanitize(event);
|
|
232
|
+
}
|
|
233
|
+
} catch (final Throwable e) {
|
|
234
|
+
drop(callback);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
final String url;
|
|
238
|
+
final String id;
|
|
239
|
+
try {
|
|
240
|
+
url = event.getUrl();
|
|
241
|
+
id = event.getId();
|
|
242
|
+
} catch (final Throwable e) {
|
|
243
|
+
drop(callback);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
final Sink current = sink.get();
|
|
247
|
+
// A null URL cannot tell a recycled entry (reset nulls the URL) from
|
|
248
|
+
// the one we were asked about, so it is dropped rather than lent.
|
|
249
|
+
if (url == null || current == null) {
|
|
250
|
+
drop(callback);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
final String eventJson;
|
|
254
|
+
try {
|
|
255
|
+
eventJson = snapshot(event);
|
|
256
|
+
} catch (final Throwable e) {
|
|
257
|
+
drop(callback);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
final String requestId = Long.toString(ids.incrementAndGet());
|
|
261
|
+
final Pending item = new Pending(requestId, event, id, url, callback, current);
|
|
262
|
+
pending.put(requestId, item);
|
|
263
|
+
try {
|
|
264
|
+
item.deadline = scheduler.schedule(() -> forget(requestId), BORROW_MS);
|
|
265
|
+
current.onNetworkFilterRequest(requestId, eventJson);
|
|
266
|
+
} catch (final Throwable e) {
|
|
267
|
+
if (pending.remove(requestId, item)) {
|
|
268
|
+
cancel(item.deadline);
|
|
269
|
+
drop(callback);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The SDK has recycled the entry, or is about to. Forget the request and
|
|
276
|
+
* do not call the callback: calling it would pass the original event
|
|
277
|
+
* through, or touch an entry that now belongs to another event.
|
|
278
|
+
*/
|
|
279
|
+
private void forget(@NonNull final String id) {
|
|
280
|
+
pending.remove(id);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The same read the capture provider uses when it decides to sanitize:
|
|
285
|
+
* {@link Options#CaptureNetworkUseDefaultSanitizer} with default
|
|
286
|
+
* {@link Boolean#TRUE}. A false value leaves the event alone.
|
|
287
|
+
*/
|
|
288
|
+
private static boolean readDefaultSanitizerOption() {
|
|
289
|
+
return readDefaultSanitizerOption(Bugsee.getLaunchOptions());
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
static boolean readDefaultSanitizerOption(@NonNull final OptionsContainer options) {
|
|
293
|
+
final Object value = options.getOption(
|
|
294
|
+
Options.CaptureNetworkUseDefaultSanitizer,
|
|
295
|
+
Boolean.TRUE
|
|
296
|
+
);
|
|
297
|
+
return ((Boolean) value).booleanValue();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** The entry is still the SDK's borrow of the event we were asked to filter. */
|
|
301
|
+
private static boolean stillBorrowed(@NonNull final Pending item) {
|
|
302
|
+
try {
|
|
303
|
+
return Objects.equals(item.originalId, item.event.getId())
|
|
304
|
+
&& Objects.equals(item.originalUrl, item.event.getUrl());
|
|
305
|
+
} catch (final Throwable ignored) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Writes the replacement onto {@code event}. Returns false when the
|
|
312
|
+
* JSON is not an event object, a field is an illegal type, or a write
|
|
313
|
+
* does not stick.
|
|
314
|
+
*/
|
|
315
|
+
private static boolean apply(@NonNull final NetworkEvent event, @NonNull final String eventJson)
|
|
316
|
+
throws JSONException {
|
|
317
|
+
final JSONObject object = new JSONObject(eventJson);
|
|
318
|
+
if (object.has("url") && !applyUrl(event, object)) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
if (object.has("body") && !applyBody(event, object)) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
if (object.has("errorDescription")
|
|
325
|
+
&& !applyString(object, "errorDescription", event::getErrorDescription, event::setErrorDescription)) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
if (object.has("errorShortMessage")
|
|
329
|
+
&& !applyString(object, "errorShortMessage", event::getErrorShortMessage, event::setErrorShortMessage)) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
if (object.has("statusText")
|
|
333
|
+
&& !applyString(object, "statusText", event::getStatusText, event::setStatusText)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
return !object.has("headers") || applyHeaders(event, object);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private static boolean applyString(
|
|
340
|
+
@NonNull final JSONObject object,
|
|
341
|
+
@NonNull final String key,
|
|
342
|
+
@NonNull final Supplier<String> get,
|
|
343
|
+
@NonNull final Consumer<String> set
|
|
344
|
+
) throws JSONException {
|
|
345
|
+
if (object.isNull(key)) {
|
|
346
|
+
set.accept(null);
|
|
347
|
+
return get.get() == null;
|
|
348
|
+
}
|
|
349
|
+
final Object raw = object.get(key);
|
|
350
|
+
if (!(raw instanceof String)) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
final String value = (String) raw;
|
|
354
|
+
set.accept(value);
|
|
355
|
+
return value.equals(get.get());
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private static boolean applyUrl(@NonNull final NetworkEvent event, @NonNull final JSONObject object)
|
|
359
|
+
throws JSONException {
|
|
360
|
+
if (object.isNull("url")) {
|
|
361
|
+
event.setUrl(null);
|
|
362
|
+
return event.getUrl() == null;
|
|
363
|
+
}
|
|
364
|
+
final Object raw = object.get("url");
|
|
365
|
+
if (!(raw instanceof String)) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
final String url = (String) raw;
|
|
369
|
+
event.setUrl(url);
|
|
370
|
+
return url.equals(event.getUrl());
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private static boolean applyBody(@NonNull final NetworkEvent event, @NonNull final JSONObject object)
|
|
374
|
+
throws JSONException {
|
|
375
|
+
if (object.isNull("body")) {
|
|
376
|
+
event.setBody(null);
|
|
377
|
+
return event.getBody() == null;
|
|
378
|
+
}
|
|
379
|
+
final Object raw = object.get("body");
|
|
380
|
+
if (!(raw instanceof String)) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
final String body = (String) raw;
|
|
384
|
+
event.setBody(body);
|
|
385
|
+
return body.equals(event.getBody());
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private static boolean applyHeaders(@NonNull final NetworkEvent event, @NonNull final JSONObject object)
|
|
389
|
+
throws JSONException {
|
|
390
|
+
if (object.isNull("headers")) {
|
|
391
|
+
event.setHeaders(null);
|
|
392
|
+
return event.getHeaders() == null;
|
|
393
|
+
}
|
|
394
|
+
final Object raw = object.get("headers");
|
|
395
|
+
if (!(raw instanceof JSONObject)) {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
final JSONObject headers = (JSONObject) raw;
|
|
399
|
+
final Map<String, String> map = new HashMap<>();
|
|
400
|
+
final Iterator<String> keys = headers.keys();
|
|
401
|
+
while (keys.hasNext()) {
|
|
402
|
+
final String key = keys.next();
|
|
403
|
+
final Object value = headers.get(key);
|
|
404
|
+
if (!(value instanceof String)) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
map.put(key, (String) value);
|
|
408
|
+
}
|
|
409
|
+
event.setHeaders(map);
|
|
410
|
+
return map.equals(event.getHeaders());
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
@NonNull
|
|
414
|
+
private static String snapshot(@NonNull final NetworkEvent event) throws JSONException {
|
|
415
|
+
final JSONObject object = new JSONObject();
|
|
416
|
+
put(object, "id", event.getId());
|
|
417
|
+
put(object, "url", event.getUrl());
|
|
418
|
+
put(object, "method", event.getMethod());
|
|
419
|
+
put(object, "body", event.getBody());
|
|
420
|
+
put(object, "errorDescription", event.getErrorDescription());
|
|
421
|
+
put(object, "errorShortMessage", event.getErrorShortMessage());
|
|
422
|
+
put(object, "statusText", event.getStatusText());
|
|
423
|
+
put(object, "mechanism", event.getMechanism());
|
|
424
|
+
final NetworkEvent.NetworkEventStage stage = event.getNetworkEventType();
|
|
425
|
+
put(object, "type", stage == null ? null : stage.toString());
|
|
426
|
+
final NetworkEvent.WebSocketEventType websocket = event.getWebSocketEventType();
|
|
427
|
+
final String websocketEvent = stage == NetworkEvent.NetworkEventStage.WebSocket && websocket != null
|
|
428
|
+
? websocket.getValue()
|
|
429
|
+
: null;
|
|
430
|
+
put(object, "websocketEvent", websocketEvent);
|
|
431
|
+
object.put("responseCode", event.getResponseCode());
|
|
432
|
+
// Read-only. Since Android 7.3.1 a request can reach the filter as more
|
|
433
|
+
// than one event with the same id: a supplement (typically the request
|
|
434
|
+
// body, known only once it is written) has isOverride() true.
|
|
435
|
+
object.put("override", event.isOverride());
|
|
436
|
+
final Map<String, String> headers = event.getHeaders();
|
|
437
|
+
if (headers == null) {
|
|
438
|
+
object.put("headers", JSONObject.NULL);
|
|
439
|
+
} else {
|
|
440
|
+
final JSONObject headerJson = new JSONObject();
|
|
441
|
+
for (final Map.Entry<String, String> entry : headers.entrySet()) {
|
|
442
|
+
if (entry.getKey() != null && entry.getValue() != null) {
|
|
443
|
+
headerJson.put(entry.getKey(), entry.getValue());
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
object.put("headers", headerJson);
|
|
447
|
+
}
|
|
448
|
+
return object.toString();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
private static void put(
|
|
452
|
+
@NonNull final JSONObject object,
|
|
453
|
+
@NonNull final String key,
|
|
454
|
+
@Nullable final String value
|
|
455
|
+
) throws JSONException {
|
|
456
|
+
object.put(key, value == null ? JSONObject.NULL : value);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
private static void cancel(@Nullable final Cancellable deadline) {
|
|
460
|
+
if (deadline == null) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
try {
|
|
464
|
+
deadline.cancel();
|
|
465
|
+
} catch (final Throwable ignored) {
|
|
466
|
+
// A timer that cannot be cancelled still only forgets the pending.
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
private static void drop(@NonNull final Callback1<NetworkEvent> callback) {
|
|
471
|
+
try {
|
|
472
|
+
callback.run(null);
|
|
473
|
+
} catch (final Throwable ignored) {
|
|
474
|
+
// The SDK already treats a throw from the callback as a drop.
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** One daemon thread, started on first use, for every request's deadline. */
|
|
479
|
+
private static final class DaemonScheduler implements Scheduler {
|
|
480
|
+
private final ScheduledThreadPoolExecutor executor;
|
|
481
|
+
|
|
482
|
+
DaemonScheduler() {
|
|
483
|
+
executor = new ScheduledThreadPoolExecutor(1, runnable -> {
|
|
484
|
+
final Thread thread = new Thread(runnable, "BugseeRN-NetworkFilterDeadline");
|
|
485
|
+
thread.setDaemon(true);
|
|
486
|
+
return thread;
|
|
487
|
+
});
|
|
488
|
+
executor.setRemoveOnCancelPolicy(true);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
@Override
|
|
492
|
+
@NonNull
|
|
493
|
+
public Cancellable schedule(@NonNull final Runnable task, final long delayMs) {
|
|
494
|
+
final ScheduledFuture<?> future = executor.schedule(task, delayMs, TimeUnit.MILLISECONDS);
|
|
495
|
+
return () -> future.cancel(false);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import java.io.Serializable;
|
|
7
|
+
import java.util.HashMap;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Expo config plugin's {@code endpoint} option at runtime.
|
|
12
|
+
*
|
|
13
|
+
* <p>The plugin writes it as application meta-data under {@link #META_DATA_KEY},
|
|
14
|
+
* a name only it uses. {@code launch()} and {@code relaunch()} then use it as
|
|
15
|
+
* the SDK's endpoint whenever JS passed none, so the reports go where the
|
|
16
|
+
* build's uploads went. An endpoint JS passed always wins. Without the
|
|
17
|
+
* meta-data nothing changes: the SDK keeps its own default.
|
|
18
|
+
*/
|
|
19
|
+
public final class PluginEndpoint {
|
|
20
|
+
|
|
21
|
+
/** Written by plugin/src/manifest.ts (RN_ENDPOINT_META_DATA). */
|
|
22
|
+
public static final String META_DATA_KEY = "com.bugsee.reactnative.endpoint";
|
|
23
|
+
|
|
24
|
+
/** The Android SDK's endpoint option (src/options/endpoint.ts). */
|
|
25
|
+
static final String OPTION_KEY = "com.bugsee.option.$$ENDPOINT";
|
|
26
|
+
|
|
27
|
+
private PluginEndpoint() {}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* {@code options} with the configured endpoint added when it has none of
|
|
31
|
+
* its own, or {@code options} itself. A blank configured value is no
|
|
32
|
+
* value. The input is never modified.
|
|
33
|
+
*/
|
|
34
|
+
@NonNull
|
|
35
|
+
public static Map<String, Serializable> withDefault(
|
|
36
|
+
@NonNull final Map<String, Serializable> options, @Nullable final String configured) {
|
|
37
|
+
if (configured == null || options.containsKey(OPTION_KEY)) {
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
final String value = configured.trim();
|
|
41
|
+
if (value.isEmpty()) {
|
|
42
|
+
return options;
|
|
43
|
+
}
|
|
44
|
+
final Map<String, Serializable> result = new HashMap<>(options);
|
|
45
|
+
result.put(OPTION_KEY, value);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The backend routes React Native JS exceptions on this class name (worker:
|
|
7
|
+
* {@code 'ReactNativeWebException' in name}). {@code consumer-rules.pro} keeps
|
|
8
|
+
* the name through R8. Never rename or nest it.
|
|
9
|
+
*
|
|
10
|
+
* <p>Extends {@link Throwable} (not {@link Exception}): 6.x wrote
|
|
11
|
+
* {@code exception_type "throwable"} in {@code crash.json}, and the reason is
|
|
12
|
+
* the JSON payload verbatim in {@link #getMessage()}.
|
|
13
|
+
*/
|
|
14
|
+
final class ReactNativeWebException extends Throwable {
|
|
15
|
+
|
|
16
|
+
ReactNativeWebException(@NonNull final String payloadJson) {
|
|
17
|
+
super(payloadJson);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
|
|
7
|
+
import com.bugsee.library.BugseeExtensionInitProviderBase;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Registers the React Native wrapper with the SDK before the SDK can launch.
|
|
11
|
+
*
|
|
12
|
+
* <p>The wrapper used to be registered from JavaScript, immediately before
|
|
13
|
+
* {@code launch()}. That is early enough when the app launches Bugsee itself
|
|
14
|
+
* from JS, and far too late otherwise: under auto-init the SDK launches from
|
|
15
|
+
* its own {@code BugseeInitProvider}, a {@link android.content.ContentProvider}
|
|
16
|
+
* that runs before {@code Application.onCreate} — before any app code exists,
|
|
17
|
+
* let alone a JS runtime. Anything the SDK does during that launch, including
|
|
18
|
+
* dispatching report handlers for a crash recovered from the previous run,
|
|
19
|
+
* happens with no wrapper registered and is silently skipped.
|
|
20
|
+
*
|
|
21
|
+
* <p>A provider at {@code initOrder="200"} is the only hook that runs earlier,
|
|
22
|
+
* and it is the convention the SDK's own extension modules already use.
|
|
23
|
+
*
|
|
24
|
+
* <p>What is registered here is deliberately the identity half of the contract
|
|
25
|
+
* and nothing else. Type and version are compile-time constants, so they are
|
|
26
|
+
* knowable with no runtime at all. The rest — the React Native version, the JS
|
|
27
|
+
* engine, whether this is a dev build — is knowable only in JS, and
|
|
28
|
+
* {@code setWrapperInfo} replaces this registration with the full one once the
|
|
29
|
+
* bridge is up. An early report is therefore attributed to
|
|
30
|
+
* {@code react_native} with a correct wrapper version and an empty context,
|
|
31
|
+
* which is strictly better than the alternative of no attribution at all.
|
|
32
|
+
*/
|
|
33
|
+
public final class ReactNativeWrapperInitProvider extends BugseeExtensionInitProviderBase {
|
|
34
|
+
|
|
35
|
+
private static final String TAG = "BugseeRN";
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
protected boolean onExtensionCreate() {
|
|
39
|
+
// Through the registrar, like every registration: setWrapperInfo
|
|
40
|
+
// re-registers from another thread once JS is up.
|
|
41
|
+
registerEarly(WrapperRegistrar::register);
|
|
42
|
+
// Conventional for an init provider: we expose no content.
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Never throws, errors included. This runs before
|
|
48
|
+
* {@code Application.onCreate} in every host app that links the library,
|
|
49
|
+
* so a throw here kills the process before the app runs a line of its
|
|
50
|
+
* own. Losing the early registration only costs attribution until
|
|
51
|
+
* {@code setWrapperInfo} registers from JS.
|
|
52
|
+
*/
|
|
53
|
+
static void registerEarly(@NonNull final WrapperRegistrar.Setter register) {
|
|
54
|
+
try {
|
|
55
|
+
register.set(BugseeReactNativeWrapper.withoutJsRuntime());
|
|
56
|
+
} catch (Throwable t) {
|
|
57
|
+
Log.e(TAG, "could not register the React Native wrapper at process start: "
|
|
58
|
+
+ t.getClass().getName());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|