Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rn-android-ignore-javascript-exception.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/react-native-plugin/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Comment thread
turnipdabeets marked this conversation as resolved.
Resolved

// 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;
Expand Down Expand Up @@ -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,
Expand Down
Loading