Skip to content

Commit

Permalink
load js by default
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Feb 10, 2025
1 parent b2409ce commit da68a4e
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 31 deletions.
3 changes: 0 additions & 3 deletions flutter/example/integration_test/web_sdk_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void main() {
testWidgets('Sentry JS SDK initialized', (tester) async {
await restoreFlutterOnErrorAfter(() async {
await SentryFlutter.init((options) {
options.enableSentryJs = true;
options.dsn = fakeDsn;
}, appRunner: () async {
await tester.pumpWidget(const app.MyApp());
Expand All @@ -77,7 +76,6 @@ void main() {

await restoreFlutterOnErrorAfter(() async {
await SentryFlutter.init((options) {
options.enableSentryJs = true;
options.dsn = fakeDsn;
options.beforeSend = (event, hint) {
dartEvent = event;
Expand Down Expand Up @@ -130,7 +128,6 @@ void main() {
testWidgets('Sentry JS SDK is not initialized', (tester) async {
await restoreFlutterOnErrorAfter(() async {
await SentryFlutter.init((options) {
options.enableSentryJs = false;
options.dsn = fakeDsn;
}, appRunner: () async {
await tester.pumpWidget(const app.MyApp());
Expand Down
1 change: 0 additions & 1 deletion flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Future<void> setupSentry(
options.debug = kDebugMode;
options.spotlight = Spotlight(enabled: true);
options.enableTimeToFullDisplayTracing = true;
options.enableSentryJs = true;

options.maxRequestBodySize = MaxRequestBodySize.always;
options.maxResponseBodySize = MaxResponseBodySize.always;
Expand Down
6 changes: 1 addition & 5 deletions flutter/lib/src/integrations/web_sdk_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:sentry/sentry.dart';

import '../native/sentry_native_binding.dart';
import '../sentry_flutter_options.dart';
import '../web/javascript_transport.dart';
import '../web/script_loader/sentry_script_loader.dart';
import '../web/sentry_js_bundle.dart';

Expand All @@ -27,7 +26,7 @@ class WebSdkIntegration implements Integration<SentryFlutterOptions> {

@override
FutureOr<void> call(Hub hub, SentryFlutterOptions options) async {
if (!options.enableSentryJs || !options.autoInitializeNativeSdk) {
if (!options.autoInitializeNativeSdk) {
return;
}

Expand All @@ -39,9 +38,6 @@ class WebSdkIntegration implements Integration<SentryFlutterOptions> {
: productionScripts;
await _scriptLoader.loadWebSdk(scripts);
await _web.init(hub);
if (_web.supportsCaptureEnvelope) {
options.transport = JavascriptTransport(_web, options);
}
options.sdk.addIntegration(name);
} catch (exception, stackTrace) {
options.logger(
Expand Down
6 changes: 3 additions & 3 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'renderer/renderer.dart';
import 'replay/integration.dart';
import 'version.dart';
import 'view_hierarchy/view_hierarchy_integration.dart';
import 'web/javascript_transport.dart';

/// Configuration options callback
typedef FlutterOptionsConfiguration = FutureOr<void> Function(
Expand Down Expand Up @@ -118,11 +119,10 @@ mixin SentryFlutter {
// Not all platforms have a native integration.
if (_native != null) {
if (_native!.supportsCaptureEnvelope) {
// Sentry's native web integration is only enabled when enableSentryJs=true.
// Transport configuration happens in web_integration because the configuration
// options aren't available until after the options callback executes.
if (!options.platformChecker.isWeb) {
options.transport = FileSystemTransport(_native!, options);
} else {
options.transport = JavascriptTransport(_native!, options);

Check warning on line 125 in flutter/lib/src/sentry_flutter.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/sentry_flutter.dart#L125

Added line #L125 was not covered by tests
}
}
if (!options.platformChecker.isWeb) {
Expand Down
7 changes: 0 additions & 7 deletions flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ class SentryFlutterOptions extends SentryOptions {
/// you must use `SentryWidgetsFlutterBinding.ensureInitialized()` instead.
bool enableFramesTracking = true;

/// Controls initialization of the Sentry Javascript SDK on web platforms.
/// When enabled and [autoInitializeNativeSdk] is true, loads and initializes
/// the JS SDK in the document head.
///
/// Defaults to `false`
bool enableSentryJs = false;

/// By using this, you are disabling native [Breadcrumb] tracking and instead
/// you are just tracking [Breadcrumb]s which result from events available
/// in the current Flutter environment.
Expand Down
12 changes: 0 additions & 12 deletions flutter/test/integrations/web_sdk_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void main() {

group('enabled', () {
setUp(() {
fixture.options.enableSentryJs = true;
fixture.options.autoInitializeNativeSdk = true;
});

Expand All @@ -52,17 +51,9 @@ void main() {
_TestScenario(
'with autoInitializeNativeSdk=false',
() {
fixture.options.enableSentryJs = true;
fixture.options.autoInitializeNativeSdk = false;
},
),
_TestScenario(
'with enableSentryJs=false',
() {
fixture.options.enableSentryJs = false;
fixture.options.autoInitializeNativeSdk = true;
},
),
];

for (final scenario in disabledScenarios) {
Expand All @@ -86,7 +77,6 @@ void main() {

group('transport configuration', () {
test('integration disabled: does not use javascript transport', () async {
fixture.options.enableSentryJs = false;
fixture.options.autoInitializeNativeSdk = false;

expect(fixture.options.transport, isA<NoOpTransport>());
Expand All @@ -99,7 +89,6 @@ void main() {
test(
'integration enabled and supportsCaptureEnvelope is false: does not use javascript transport',
() async {
fixture.options.enableSentryJs = true;
fixture.options.autoInitializeNativeSdk = true;
when(fixture.web.supportsCaptureEnvelope).thenReturn(false);

Expand All @@ -113,7 +102,6 @@ void main() {
test(
'integration enabled and supportsCaptureEnvelope is true: uses javascript transport',
() async {
fixture.options.enableSentryJs = true;
fixture.options.autoInitializeNativeSdk = true;

expect(fixture.options.transport, isA<NoOpTransport>());
Expand Down

0 comments on commit da68a4e

Please sign in to comment.