Skip to content

Commit 821fef9

Browse files
committed
Ignore JavascriptException by default
1 parent 58e6e9c commit 821fef9

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryStartTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class RNSentryStartTest {
6363
}
6464

6565
@Test
66-
fun `the JavascriptException is added to the ignoredExceptionsForType list on initialisation`() {
66+
fun `the JavascriptException is added to the ignoredExceptionsForType list on with react defaults`() {
6767
val actualOptions = SentryAndroidOptions()
68-
RNSentryStart.getSentryAndroidOptions(actualOptions, JavaOnlyMap.of(), activity, logger)
68+
RNSentryStart.updateWithReactDefaults(actualOptions)
6969
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
7070
}
7171

packages/core/android/src/main/java/io/sentry/react/RNSentryStart.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ static void getSentryAndroidOptions(
194194
return breadcrumb;
195195
});
196196

197-
// React native internally throws a JavascriptException.
198-
// we want to ignore it on the native side to avoid sending it twice.
199-
options.addIgnoredExceptionForType(JavascriptException.class);
200-
201197
if (rnOptions.hasKey("enableNativeCrashHandling")
202198
&& !rnOptions.getBoolean("enableNativeCrashHandling")) {
203199
final List<Integration> integrations = options.getIntegrations();
@@ -224,6 +220,10 @@ static void updateWithReactDefaults(@NotNull SentryAndroidOptions options) {
224220
options.setTracesSampleRate(null);
225221
options.setTracesSampler(null);
226222
options.setEnableTracing(false);
223+
224+
// React native internally throws a JavascriptException.
225+
// we want to ignore it on the native side to avoid sending it twice.
226+
options.addIgnoredExceptionForType(JavascriptException.class);
227227
}
228228

229229
/**
@@ -234,14 +234,6 @@ static void updateWithReactFinals(@NotNull SentryAndroidOptions options) {
234234
BeforeSendCallback userBeforeSend = options.getBeforeSend();
235235
options.setBeforeSend(
236236
(event, hint) -> {
237-
// Unhandled JS Exception are processed by the SDK on JS layer
238-
// To avoid duplicates we drop them in the native SDKs
239-
if (event.getExceptions() != null && !event.getExceptions().isEmpty()) {
240-
String exType = event.getExceptions().get(0).getType();
241-
if (exType != null && exType.contains("Unhandled JS Exception")) {
242-
return null; // Skip sending this event
243-
}
244-
}
245237
setEventOriginTag(event);
246238
addPackages(event, options.getSdkVersion());
247239
if (userBeforeSend != null) {

0 commit comments

Comments
 (0)