Skip to content

Commit

Permalink
Ignore JavascriptException by default
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Feb 3, 2025
1 parent 58e6e9c commit 821fef9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class RNSentryStartTest {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ static void getSentryAndroidOptions(
return breadcrumb;
});

// React native internally throws a JavascriptException.
// we want to ignore it on the native side to avoid sending it twice.
options.addIgnoredExceptionForType(JavascriptException.class);

if (rnOptions.hasKey("enableNativeCrashHandling")
&& !rnOptions.getBoolean("enableNativeCrashHandling")) {
final List<Integration> integrations = options.getIntegrations();
Expand All @@ -224,6 +220,10 @@ static void updateWithReactDefaults(@NotNull SentryAndroidOptions options) {
options.setTracesSampleRate(null);
options.setTracesSampler(null);
options.setEnableTracing(false);

// React native internally throws a JavascriptException.
// we want to ignore it on the native side to avoid sending it twice.
options.addIgnoredExceptionForType(JavascriptException.class);
}

/**
Expand All @@ -234,14 +234,6 @@ static void updateWithReactFinals(@NotNull SentryAndroidOptions options) {
BeforeSendCallback userBeforeSend = options.getBeforeSend();
options.setBeforeSend(
(event, hint) -> {
// Unhandled JS Exception are processed by the SDK on JS layer
// To avoid duplicates we drop them in the native SDKs
if (event.getExceptions() != null && !event.getExceptions().isEmpty()) {
String exType = event.getExceptions().get(0).getType();
if (exType != null && exType.contains("Unhandled JS Exception")) {
return null; // Skip sending this event
}
}
setEventOriginTag(event);
addPackages(event, options.getSdkVersion());
if (userBeforeSend != null) {
Expand Down

0 comments on commit 821fef9

Please sign in to comment.