@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.
Files changed (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +552 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +944 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,251 @@
1
+ #import "BGSRNReactWindow.h"
2
+
3
+ const NSUInteger BGSRNReactRootSearchBudget = 2000;
4
+
5
+ const NSUInteger BGSRNModalHostSearchBudget = 10000;
6
+
7
+ /// Whether the SDK composes the app's windows on the screen: iOS, and not an
8
+ /// iPhone or iPad app running on a Mac (`+[BGSTrackerApplication
9
+ /// capturesAppScreen]`).
10
+ static BOOL BGSRNSdkComposesScreen(void) {
11
+ #if TARGET_OS_MACCATALYST
12
+ return NO;
13
+ #else
14
+ return !NSProcessInfo.processInfo.isiOSAppOnMac;
15
+ #endif
16
+ }
17
+
18
+ /// A window scene the user can see: the SDK leaves background scenes out, as
19
+ /// they keep reporting their last place on a screen.
20
+ static BOOL BGSRNIsForeground(UIScene *scene) {
21
+ return scene.activationState == UISceneActivationStateForegroundActive ||
22
+ scene.activationState == UISceneActivationStateForegroundInactive;
23
+ }
24
+
25
+ UIWindow *BGSRNSdkKeyWindow(void) {
26
+ UIApplication *application = UIApplication.sharedApplication;
27
+ if (application == nil) {
28
+ return nil;
29
+ }
30
+ // Since the iOS 15 SDK every scene's key window reports isKeyWindow, so with
31
+ // two of the app's scenes on screen the loop below cannot tell which one the
32
+ // user is in; the application's key window follows the one brought forward.
33
+ #pragma clang diagnostic push
34
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
35
+ UIWindow *applicationKeyWindow = application.keyWindow;
36
+ #pragma clang diagnostic pop
37
+ if (applicationKeyWindow.windowScene != nil && BGSRNIsForeground(applicationKeyWindow.windowScene)) {
38
+ return applicationKeyWindow;
39
+ }
40
+ UIWindow *fallback = nil;
41
+ UIWindow *stableForeground = nil;
42
+ UIWindow *markedKey = nil;
43
+ for (UIScene *scene in application.connectedScenes) {
44
+ if (![scene isKindOfClass:UIWindowScene.class]) {
45
+ continue;
46
+ }
47
+ UIWindow *sceneKey = ((UIWindowScene *)scene).keyWindow;
48
+ if (sceneKey == nil) {
49
+ continue;
50
+ }
51
+ fallback = sceneKey;
52
+ if (scene.activationState != UISceneActivationStateForegroundActive) {
53
+ continue;
54
+ }
55
+ if (sceneKey.isKeyWindow) {
56
+ markedKey = sceneKey;
57
+ }
58
+ if (stableForeground == nil) {
59
+ stableForeground = sceneKey;
60
+ }
61
+ }
62
+ if (fallback == nil) {
63
+ // The SDK's own last resort, deprecated but still what it reads.
64
+ #pragma clang diagnostic push
65
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
66
+ fallback = application.keyWindow;
67
+ #pragma clang diagnostic pop
68
+ }
69
+ return markedKey ?: (stableForeground ?: fallback);
70
+ }
71
+
72
+ NSArray<UIWindow *> *BGSRNSdkWalkedWindows(UIWindow *keyWindow) {
73
+ if (keyWindow == nil) {
74
+ return @[];
75
+ }
76
+ static BOOL hasSceneManifest = NO;
77
+ static dispatch_once_t once;
78
+ dispatch_once(&once, ^{
79
+ NSDictionary *manifest = [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIApplicationSceneManifest"];
80
+ hasSceneManifest = [manifest isKindOfClass:NSDictionary.class] && manifest.count > 0;
81
+ });
82
+ UIApplication *application = UIApplication.sharedApplication;
83
+ UIScreen *screen = keyWindow.windowScene.screen;
84
+ if (hasSceneManifest && BGSRNSdkComposesScreen() && application.connectedScenes.count > 1 &&
85
+ screen != nil) {
86
+ NSMutableArray<UIWindow *> *composed = [NSMutableArray array];
87
+ for (UIScene *scene in application.connectedScenes) {
88
+ if ([scene isKindOfClass:UIWindowScene.class] && BGSRNIsForeground(scene) &&
89
+ ((UIWindowScene *)scene).screen == screen) {
90
+ [composed addObjectsFromArray:((UIWindowScene *)scene).windows];
91
+ }
92
+ }
93
+ if (composed.count > 0) {
94
+ return composed;
95
+ }
96
+ }
97
+ NSArray<UIWindow *> *windows = nil;
98
+ if (hasSceneManifest) {
99
+ windows = keyWindow.windowScene.windows;
100
+ } else {
101
+ #pragma clang diagnostic push
102
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
103
+ windows = application.windows;
104
+ #pragma clang diagnostic pop
105
+ }
106
+ return windows ?: @[];
107
+ }
108
+
109
+ /// Breadth-first: a React root is near the top of its window, and a deep
110
+ /// native subtree beside it should not be searched first.
111
+ static UIView *ReactRootInWindow(UIWindow *window, BOOL (^isReactRoot)(UIView *), NSUInteger budget) {
112
+ NSMutableArray<UIView *> *queue = [NSMutableArray arrayWithObject:window];
113
+ NSUInteger head = 0;
114
+ while (head < queue.count && head < budget) {
115
+ UIView *view = queue[head++];
116
+ if (isReactRoot(view)) {
117
+ return view;
118
+ }
119
+ [queue addObjectsFromArray:view.subviews];
120
+ }
121
+ return nil;
122
+ }
123
+
124
+ UIView *BGSRNReactRootView(UIWindow *keyWindow,
125
+ NSArray<UIWindow *> *windows,
126
+ BOOL (^isReactRoot)(UIView *),
127
+ NSUInteger budget) {
128
+ UIView *root = keyWindow != nil ? ReactRootInWindow(keyWindow, isReactRoot, budget) : nil;
129
+ if (root != nil) {
130
+ return root;
131
+ }
132
+ for (UIWindow *window in windows) {
133
+ if (window != keyWindow) {
134
+ root = ReactRootInWindow(window, isReactRoot, budget);
135
+ if (root != nil) {
136
+ return root;
137
+ }
138
+ }
139
+ }
140
+ return nil;
141
+ }
142
+
143
+ UIWindow *BGSRNWindowHostingReactRoot(UIWindow *keyWindow,
144
+ NSArray<UIWindow *> *windows,
145
+ BOOL (^isReactRoot)(UIView *),
146
+ NSUInteger budget) {
147
+ UIView *root = BGSRNReactRootView(keyWindow, windows, isReactRoot, budget);
148
+ // A root found in a window's tree is in that window, unless it is the window itself.
149
+ return [root isKindOfClass:UIWindow.class] ? (UIWindow *)root : root.window;
150
+ }
151
+
152
+ NSValue *BGSRNReactRootOrigin(UIWindow *keyWindow, NSArray<UIWindow *> *windows, BOOL (^isReactRoot)(UIView *)) {
153
+ UIWindow *window = BGSRNWindowHostingReactRoot(keyWindow, windows, isReactRoot, BGSRNReactRootSearchBudget);
154
+ if (window == nil) {
155
+ return nil;
156
+ }
157
+ // Not `frame.origin` on iOS: that is the window's place in its scene, {0, 0}
158
+ // for a Stage Manager window or the right-hand one side by side, while the
159
+ // SDK places its nodes on the screen.
160
+ return BGSRNWindowRecordedOrigin(window);
161
+ }
162
+
163
+ NSValue *BGSRNWindowRecordedOrigin(UIWindow *window) {
164
+ UIScreen *screen = window.windowScene.screen;
165
+ if (screen == nil) {
166
+ return nil;
167
+ }
168
+ if (!BGSRNSdkComposesScreen()) {
169
+ return [NSValue valueWithCGPoint:window.frame.origin];
170
+ }
171
+ id<UICoordinateSpace> fixedSpace = screen.fixedCoordinateSpace;
172
+ const CGRect inFixedSpace = [window convertRect:window.bounds toCoordinateSpace:fixedSpace];
173
+ const CGRect onScreen = [fixedSpace convertRect:inFixedSpace
174
+ toCoordinateSpace:screen.coordinateSpace];
175
+ return [NSValue valueWithCGPoint:onScreen.origin];
176
+ }
177
+
178
+ /// A `<Modal>` host's view controller. Declared here rather than imported:
179
+ /// `RCTModalHostViewComponentView` implements `viewController` without
180
+ /// declaring it in its header, and the call is guarded by
181
+ /// `respondsToSelector:`.
182
+ @interface UIView (BGSRNModalHostController)
183
+ - (UIViewController *)viewController;
184
+ @end
185
+
186
+ UIView *BGSRNUniqueTaggedView(NSArray<UIWindow *> *windows, NSInteger tag, BOOL (^matches)(UIView *), NSUInteger budget) {
187
+ UIView *found = nil;
188
+ for (UIWindow *window in windows) {
189
+ NSMutableArray<UIView *> *queue = [NSMutableArray arrayWithObject:window];
190
+ NSUInteger head = 0;
191
+ while (head < queue.count && head < budget) {
192
+ UIView *view = queue[head++];
193
+ if (view.tag == tag && matches(view)) {
194
+ if (found != nil && found != view) {
195
+ return nil;
196
+ }
197
+ found = view;
198
+ }
199
+ [queue addObjectsFromArray:view.subviews];
200
+ }
201
+ }
202
+ return found;
203
+ }
204
+
205
+ NSValue *BGSRNModalHostOrigin(UIView *host, NSValue *_Nullable (^windowOrigin)(UIWindow *window)) {
206
+ if (![host respondsToSelector:@selector(viewController)]) {
207
+ return nil;
208
+ }
209
+ UIViewController *controller = [host viewController];
210
+ if (controller == nil || !controller.isViewLoaded) {
211
+ return nil;
212
+ }
213
+ UIView *content = controller.view;
214
+ UIWindow *window = content.window;
215
+ if (window == nil) {
216
+ return nil;
217
+ }
218
+ // The same window placement as the main surface (`BGSRNWindowRecordedOrigin`
219
+ // in the module), so both lanes share one convention.
220
+ NSValue *placed = windowOrigin(window);
221
+ if (placed == nil) {
222
+ return nil;
223
+ }
224
+ CGPoint inWindow = [content convertPoint:CGPointZero toView:nil];
225
+ CGPoint place = placed.CGPointValue;
226
+ return [NSValue valueWithCGPoint:CGPointMake(inWindow.x + place.x, inWindow.y + place.y)];
227
+ }
228
+
229
+ NSValue *BGSRNSecureSurfaceOrigin(BGSRNSecureRectangles *store,
230
+ NSInteger surface,
231
+ NSArray<UIWindow *> *windows,
232
+ BOOL (^isHost)(UIView *),
233
+ NSValue *_Nullable (^windowOrigin)(UIWindow *window)) {
234
+ UIView *host = [store hostForSurface:surface accepting:^BOOL(id candidate) {
235
+ return [candidate isKindOfClass:UIView.class] && ((UIView *)candidate).tag == surface && isHost(candidate);
236
+ }];
237
+ if (host != nil) {
238
+ // The current runtime's own host: not presented yet is no origin, not a
239
+ // search that could find another runtime's.
240
+ return BGSRNModalHostOrigin(host, windowOrigin);
241
+ }
242
+ if ([store isHostNamedForSurface:surface]) {
243
+ // Named but not found: the current runtime's host has not mounted yet
244
+ // (Fabric mounts it after the publish), or has gone. Unknown, so the lane
245
+ // fails closed: during a reload the walk's one match can be the old
246
+ // runtime's still-presented host.
247
+ return nil;
248
+ }
249
+ UIView *found = BGSRNUniqueTaggedView(windows, surface, isHost, BGSRNModalHostSearchBudget);
250
+ return found == nil ? nil : BGSRNModalHostOrigin(found, windowOrigin);
251
+ }
@@ -0,0 +1,47 @@
1
+ #import "include/BGSRNReportArgs.h"
2
+
3
+ #import <Bugsee/Bugsee.h>
4
+
5
+ const NSInteger BGSRNDefaultBugPriorityFallback = 3;
6
+
7
+ static BOOL BGSRNIntegralSeverity(id raw, NSInteger *out) {
8
+ if (![raw isKindOfClass:[NSNumber class]]) {
9
+ return NO;
10
+ }
11
+ // A boolean is an NSNumber whose integer value is 0 or 1. It is not a
12
+ // severity the launch option was given as.
13
+ if (CFGetTypeID((__bridge CFTypeRef)raw) == CFBooleanGetTypeID()) {
14
+ return NO;
15
+ }
16
+ const double value = [(NSNumber *)raw doubleValue];
17
+ if (value < 1.0 || value > 5.0 || value != (NSInteger)value) {
18
+ return NO;
19
+ }
20
+ *out = (NSInteger)value;
21
+ return YES;
22
+ }
23
+
24
+ NSInteger BGSRNUploadSeverity(NSInteger requested, NSDictionary *_Nullable launchOptions) {
25
+ if (requested >= 1 && requested <= 5) {
26
+ return requested;
27
+ }
28
+ NSInteger option = 0;
29
+ id raw = launchOptions[BugseeOptionReportingDefaultBugPriority];
30
+ if (BGSRNIntegralSeverity(raw, &option)) {
31
+ return option;
32
+ }
33
+ return BGSRNDefaultBugPriorityFallback;
34
+ }
35
+
36
+ NSArray<NSString *> *_Nullable BGSRNStringArray(NSArray *_Nullable raw) {
37
+ if (raw == nil) {
38
+ return nil;
39
+ }
40
+ NSMutableArray<NSString *> *result = [NSMutableArray arrayWithCapacity:raw.count];
41
+ for (id item in raw) {
42
+ if ([item isKindOfClass:[NSString class]]) {
43
+ [result addObject:item];
44
+ }
45
+ }
46
+ return result;
47
+ }
@@ -0,0 +1,8 @@
1
+ #import "BGSRNReportDeadlines.h"
2
+
3
+ const int64_t BGSRNLiveDeadlineMs = 25000;
4
+ const int64_t BGSRNRecoveryDeadlineMs = 2500;
5
+
6
+ int64_t BGSRNDeadlineMs(BOOL onMainThread) {
7
+ return onMainThread ? BGSRNLiveDeadlineMs : BGSRNRecoveryDeadlineMs;
8
+ }
@@ -0,0 +1,308 @@
1
+ #import "BGSRNReportHandlerBridge.h"
2
+
3
+ #import <os/lock.h>
4
+
5
+ #import "BGSRNReportDeadlines.h"
6
+
7
+ /// One dispatch that reached JS. `done`, `timer`, `report` and `completion`
8
+ /// are guarded by the bridge's lock; everything else is immutable.
9
+ @interface BGSRNReportHandle : NSObject
10
+ @property (nonatomic, copy, readonly) NSString *handleId;
11
+ /// Nilled by `finish:`, with `completion`: the deadline task captures the
12
+ /// handle, and a cancelled `dispatch_block` keeps its captures until its fire
13
+ /// time, so a finished handle would otherwise pin both for up to 25 s.
14
+ @property (nonatomic, strong, nullable) id<BGSReportContract> report;
15
+ @property (nonatomic, copy, nullable) BGSCallback completion;
16
+ /// The sink this handle was emitted to; its detach completes it. Weak, like
17
+ /// the sink itself: the bridge must not keep a torn-down module alive.
18
+ @property (nonatomic, weak, readonly) id owner;
19
+ /// The exactly-once guard. Whoever flips it runs the completion.
20
+ @property (nonatomic) BOOL done;
21
+ @property (nonatomic, strong, nullable) id timer;
22
+ @end
23
+
24
+ @implementation BGSRNReportHandle
25
+
26
+ - (instancetype)initWithId:(NSString *)handleId
27
+ report:(id<BGSReportContract>)report
28
+ completion:(BGSCallback)completion
29
+ owner:(id)owner {
30
+ self = [super init];
31
+ if (self) {
32
+ _handleId = [handleId copy];
33
+ _report = report;
34
+ _completion = [completion copy];
35
+ _owner = owner;
36
+ }
37
+ return self;
38
+ }
39
+
40
+ @end
41
+
42
+ static NSString *PhaseWire(BGSRNReportPhase phase) {
43
+ return phase == BGSRNReportPhaseBefore ? @"before" : @"after";
44
+ }
45
+
46
+ /// The SDK's own fault must not escape into JS's queue or the timer's.
47
+ static void RunQuietly(BGSCallback _Nullable completion) {
48
+ if (completion == nil) {
49
+ return;
50
+ }
51
+ @try {
52
+ completion();
53
+ } @catch (NSException *exception) {
54
+ NSLog(@"BugseeRN report handler completion threw: %@", NSStringFromClass(exception.class));
55
+ }
56
+ }
57
+
58
+ static NSString *_Nullable SafeReportId(id<BGSReportContract> report) {
59
+ @try {
60
+ return report.reportId;
61
+ } @catch (NSException *exception) {
62
+ return nil;
63
+ }
64
+ }
65
+
66
+ static NSString *_Nullable SafeType(id<BGSReportContract> report) {
67
+ @try {
68
+ return report.type;
69
+ } @catch (NSException *exception) {
70
+ return nil;
71
+ }
72
+ }
73
+
74
+ @implementation BGSRNReportHandlerBridge {
75
+ BGSRNReportScheduler _schedule;
76
+ BGSRNReportSchedulerCancel _cancel;
77
+ BGSRNReportOutcomeLog _log;
78
+
79
+ /// Guards everything below. The SDK dispatches on main (live) or its own
80
+ /// threads (recovery), JS completes and reads on the module's queue, and
81
+ /// deadlines fire on the scheduler's: all of them meet here. Never held
82
+ /// while calling out -- not the SDK's completion, not the sink, not the
83
+ /// scheduler.
84
+ os_unfair_lock _lock;
85
+ __weak id _sink;
86
+ BGSRNReportRequestBlock _block;
87
+ BOOL _beforeRegistered;
88
+ BOOL _afterRegistered;
89
+ NSMutableDictionary<NSString *, BGSRNReportHandle *> *_handles;
90
+ uint64_t _counter;
91
+ }
92
+
93
+ + (BGSRNReportHandlerBridge *)shared {
94
+ static BGSRNReportHandlerBridge *shared = nil;
95
+ static dispatch_once_t once;
96
+ dispatch_once(&once, ^{
97
+ // One serial queue for every handle's deadline. A cancelled block that has
98
+ // not started never runs; one that has already started still reaches the
99
+ // handle's guard, which is what makes cancelling safe to race.
100
+ dispatch_queue_t queue = dispatch_queue_create("com.bugsee.reactnative.report-deadline",
101
+ DISPATCH_QUEUE_SERIAL);
102
+ shared = [[BGSRNReportHandlerBridge alloc]
103
+ initWithScheduler:^id(dispatch_block_t task, int64_t delayMs) {
104
+ dispatch_block_t block = dispatch_block_create(0, task);
105
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delayMs * (int64_t)NSEC_PER_MSEC), queue, block);
106
+ return block;
107
+ }
108
+ cancel:^(id token) {
109
+ dispatch_block_cancel((dispatch_block_t)token);
110
+ }];
111
+ });
112
+ return shared;
113
+ }
114
+
115
+ - (instancetype)initWithScheduler:(BGSRNReportScheduler)schedule cancel:(BGSRNReportSchedulerCancel)cancel {
116
+ return [self initWithScheduler:schedule
117
+ cancel:cancel
118
+ log:^(NSString *line) {
119
+ // NSLog, not os_log: it reaches the
120
+ // `devicectl --console` stream the device
121
+ // tests match.
122
+ NSLog(@"%@", line);
123
+ }];
124
+ }
125
+
126
+ - (instancetype)initWithScheduler:(BGSRNReportScheduler)schedule
127
+ cancel:(BGSRNReportSchedulerCancel)cancel
128
+ log:(BGSRNReportOutcomeLog)log {
129
+ self = [super init];
130
+ if (self) {
131
+ _schedule = [schedule copy];
132
+ _cancel = [cancel copy];
133
+ _log = [log copy];
134
+ _lock = OS_UNFAIR_LOCK_INIT;
135
+ _handles = [NSMutableDictionary dictionary];
136
+ }
137
+ return self;
138
+ }
139
+
140
+ - (void)setPhasesBefore:(BOOL)before after:(BOOL)after {
141
+ os_unfair_lock_lock(&_lock);
142
+ _beforeRegistered = before;
143
+ _afterRegistered = after;
144
+ os_unfair_lock_unlock(&_lock);
145
+ }
146
+
147
+ - (void)attach:(id)sink block:(BGSRNReportRequestBlock)block {
148
+ os_unfair_lock_lock(&_lock);
149
+ _sink = sink;
150
+ _block = [block copy];
151
+ _beforeRegistered = NO;
152
+ _afterRegistered = NO;
153
+ os_unfair_lock_unlock(&_lock);
154
+ }
155
+
156
+ - (void)detach:(id)sink {
157
+ NSMutableArray<BGSRNReportHandle *> *stale = [NSMutableArray array];
158
+ os_unfair_lock_lock(&_lock);
159
+ if (_sink == sink) {
160
+ _sink = nil;
161
+ _block = nil;
162
+ _beforeRegistered = NO;
163
+ _afterRegistered = NO;
164
+ }
165
+ for (BGSRNReportHandle *handle in _handles.allValues) {
166
+ if (handle.owner == sink) {
167
+ [stale addObject:handle];
168
+ }
169
+ }
170
+ os_unfair_lock_unlock(&_lock);
171
+
172
+ for (BGSRNReportHandle *handle in stale) {
173
+ [self finish:handle by:@"detach"];
174
+ }
175
+ }
176
+
177
+ - (void)dispatchPhase:(BGSRNReportPhase)phase
178
+ report:(id<BGSReportContract>)report
179
+ isTerminating:(BOOL)isTerminating
180
+ onMainThread:(BOOL)onMain
181
+ completion:(BGSCallback)completion {
182
+ // The process dies when this returns; nothing asynchronous survives it.
183
+ // Never YES on iOS today, but the contract allows it.
184
+ if (isTerminating) {
185
+ [self completeUnmintedPhase:phase report:report completion:completion by:@"terminating"];
186
+ return;
187
+ }
188
+
189
+ os_unfair_lock_lock(&_lock);
190
+ id target = _sink;
191
+ BGSRNReportRequestBlock block = _block;
192
+ const BOOL registered = phase == BGSRNReportPhaseBefore ? _beforeRegistered : _afterRegistered;
193
+ BGSRNReportHandle *handle = nil;
194
+ if (target != nil && block != nil && registered) {
195
+ NSString *handleId = [NSString stringWithFormat:@"rh-%llu", ++_counter];
196
+ handle = [[BGSRNReportHandle alloc] initWithId:handleId report:report completion:completion owner:target];
197
+ _handles[handleId] = handle;
198
+ }
199
+ os_unfair_lock_unlock(&_lock);
200
+
201
+ if (handle == nil) {
202
+ [self completeUnmintedPhase:phase report:report completion:completion by:@"no-handler"];
203
+ return;
204
+ }
205
+
206
+ // Live (main) or recovery (off main): see BGSRNReportDeadlines.h. Unlike
207
+ // Android, recovery still reaches JS.
208
+ const int64_t deadlineMs = BGSRNDeadlineMs(onMain);
209
+ // The task holds the handle itself, not its id: a deadline that was already
210
+ // running when JS completed must still hit the guard.
211
+ id timer = _schedule(^{
212
+ [self finish:handle by:@"deadline"];
213
+ }, deadlineMs);
214
+ os_unfair_lock_lock(&_lock);
215
+ const BOOL alreadyDone = handle.done;
216
+ if (!alreadyDone) {
217
+ handle.timer = timer;
218
+ }
219
+ os_unfair_lock_unlock(&_lock);
220
+ if (alreadyDone) {
221
+ // Finished between minting and here; don't leave the timer armed.
222
+ [self cancelQuietly:timer];
223
+ }
224
+
225
+ _log([NSString stringWithFormat:@"BugseeRN report handler %@ phase=%@ deadline=%lld",
226
+ handle.handleId, PhaseWire(phase), deadlineMs]);
227
+ // Branch on the result, never @try: the sink catches inside Objective-C++
228
+ // (BGSRNGuardedEmit), and nothing may unwind through this ARC file, which
229
+ // is not built exception-safe.
230
+ const BOOL delivered = block(@{
231
+ @"handleId" : handle.handleId,
232
+ @"phase" : PhaseWire(phase),
233
+ @"reportId" : SafeReportId(report) ?: @"",
234
+ @"type" : SafeType(report) ?: @"",
235
+ @"deadlineMs" : @((double)deadlineMs),
236
+ });
237
+ if (!delivered) {
238
+ // A dead bridge, on the SDK's thread. JS will never answer, so answer for
239
+ // it now.
240
+ NSLog(@"BugseeRN report handler %@ could not reach JS", handle.handleId);
241
+ [self finish:handle by:@"no-handler"];
242
+ }
243
+ }
244
+
245
+ - (BOOL)complete:(NSString *)handleId {
246
+ os_unfair_lock_lock(&_lock);
247
+ BGSRNReportHandle *handle = _handles[handleId];
248
+ os_unfair_lock_unlock(&_lock);
249
+ return handle != nil && [self finish:handle by:@"js"];
250
+ }
251
+
252
+ - (id<BGSReportContract>)reportFor:(NSString *)handleId {
253
+ os_unfair_lock_lock(&_lock);
254
+ BGSRNReportHandle *handle = _handles[handleId];
255
+ id<BGSReportContract> report = (handle == nil || handle.done) ? nil : handle.report;
256
+ os_unfair_lock_unlock(&_lock);
257
+ return report;
258
+ }
259
+
260
+ #pragma mark - Private
261
+
262
+ /// @return YES only for the call that ran the SDK completion.
263
+ - (BOOL)finish:(BGSRNReportHandle *)handle by:(NSString *)by {
264
+ os_unfair_lock_lock(&_lock);
265
+ if (handle.done) {
266
+ os_unfair_lock_unlock(&_lock);
267
+ return NO;
268
+ }
269
+ handle.done = YES;
270
+ if (_handles[handle.handleId] == handle) {
271
+ [_handles removeObjectForKey:handle.handleId];
272
+ }
273
+ id timer = handle.timer;
274
+ handle.timer = nil;
275
+ BGSCallback completion = handle.completion;
276
+ handle.completion = nil;
277
+ handle.report = nil;
278
+ os_unfair_lock_unlock(&_lock);
279
+
280
+ // Outside the lock from here: the completion re-enters the SDK, and a
281
+ // cancel or a log line has no business holding up every other handle.
282
+ if (timer != nil) {
283
+ [self cancelQuietly:timer];
284
+ }
285
+ _log([NSString stringWithFormat:@"BugseeRN report handler %@ completed by=%@", handle.handleId, by]);
286
+ RunQuietly(completion);
287
+ return YES;
288
+ }
289
+
290
+ /// No handle was minted; the line still carries the report for correlation.
291
+ - (void)completeUnmintedPhase:(BGSRNReportPhase)phase
292
+ report:(id<BGSReportContract>)report
293
+ completion:(BGSCallback)completion
294
+ by:(NSString *)by {
295
+ _log([NSString stringWithFormat:@"BugseeRN report handler - completed by=%@ phase=%@ report=%@",
296
+ by, PhaseWire(phase), SafeReportId(report)]);
297
+ RunQuietly(completion);
298
+ }
299
+
300
+ - (void)cancelQuietly:(id)timer {
301
+ @try {
302
+ _cancel(timer);
303
+ } @catch (NSException *exception) {
304
+ NSLog(@"BugseeRN report handler timer cancel threw: %@", NSStringFromClass(exception.class));
305
+ }
306
+ }
307
+
308
+ @end