diff --git a/.changeset/rn-android-ignore-javascript-exception.md b/.changeset/rn-android-ignore-javascript-exception.md new file mode 100644 index 0000000000..5de78bd506 --- /dev/null +++ b/.changeset/rn-android-ignore-javascript-exception.md @@ -0,0 +1,5 @@ +--- +'@posthog/react-native-plugin': patch +--- + +Fix fatal JS errors being double-reported on Android in minified release builds: the plugin's dedup matched serialized class-name strings, which R8/ProGuard renaming can defeat. It now registers `JavascriptException` in posthog-android's `errorTrackingConfig.ignoredExceptionTypes` (requires core 6.24.0), which matches by class across the cause chain and is unaffected by minification. diff --git a/packages/react-native-plugin/android/build.gradle b/packages/react-native-plugin/android/build.gradle index ec582e7076..e71a2dcb24 100644 --- a/packages/react-native-plugin/android/build.gradle +++ b/packages/react-native-plugin/android/build.gradle @@ -85,6 +85,6 @@ dependencies { //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation "com.posthog:posthog-android:3.52.0" + implementation "com.posthog:posthog-android:3.53.6" } diff --git a/packages/react-native-plugin/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt b/packages/react-native-plugin/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt index fb9439db07..1010325458 100644 --- a/packages/react-native-plugin/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt +++ b/packages/react-native-plugin/android/src/main/java/com/posthogreactnativeplugin/PosthogReactNativePluginModule.kt @@ -7,9 +7,9 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.UiThreadUtil +import com.facebook.react.common.JavascriptException import com.posthog.PostHog import com.posthog.PostHogConfig -import com.posthog.PostHogEvent import com.posthog.android.PostHogAndroid import com.posthog.android.PostHogAndroidConfig import com.posthog.internal.PostHogPreferences @@ -117,7 +117,7 @@ class PosthogReactNativePluginModule( // React Native rethrows fatal JS errors natively as JavascriptException. // The JS layer already captured them, so drop the native duplicate. - addBeforeSend { event -> if (isReactNativeFatalJsError(event)) null else event } + errorTrackingConfig.ignoredExceptionTypes.add(JavascriptException::class.java) // Always apply the session replay configuration so that recording started later // (e.g. startRecording or a linked feature flag) uses the right mode and masking; @@ -320,16 +320,6 @@ class PosthogReactNativePluginModule( key: String, ): Double? = runCatching { if (hasKey(map, key)) map?.getDouble(key) else null }.getOrNull() - private fun isReactNativeFatalJsError(event: PostHogEvent): Boolean { - if (event.event != "\$exception") return false - val exceptionList = event.properties?.get("\$exception_list") as? List<*> ?: return false - return exceptionList.any { item -> - val exception = item as? Map<*, *> ?: return@any false - exception["type"] == "JavascriptException" && - (exception["module"] as? String)?.startsWith("com.facebook.react") == true - } - } - private fun logError( method: String, error: Throwable,