From 9766800d838fbb4858b0c002f398b1ce6c704995 Mon Sep 17 00:00:00 2001 From: Giancarlo Buenaflor Date: Thu, 13 Feb 2025 16:40:18 +0100 Subject: [PATCH] [v9]: Remove `dart:html` usage in favour of `package:web` (#2710) * remove dart:html usage and used package:web instead * update CHANGELOG and remove publish validation * remove publish validation from ci * update web_example dep * update * remove more conditionals --- .github/workflows/analyze.yml | 5 - CHANGELOG.md | 1 + dart/example_web/pubspec.yaml | 2 +- .../src/dart_exception_type_identifier.dart | 1 - .../environment/environment_variables.dart | 1 - .../enricher/enricher_event_processor.dart | 1 - .../html_enricher_event_processor.dart | 104 ------------------ .../web_enricher_event_processor.dart | 2 - .../exception/exception_event_processor.dart | 1 - dart/lib/src/origin.dart | 4 +- dart/lib/src/origin_html.dart | 5 - dart/lib/src/origin_web.dart | 2 - dart/lib/src/platform/_html_platform.dart | 53 --------- dart/lib/src/platform/_web_platform.dart | 2 - dart/lib/src/platform/platform.dart | 5 +- dart/lib/src/utils/isolate_utils.dart | 1 - dart/pubspec.yaml | 1 + .../enricher/web_enricher_test.dart | 4 +- file/lib/src/sentry_file_extension.dart | 8 +- .../html_url_filter_event_processor.dart | 39 ------- .../url_filter_event_processor.dart | 1 - .../web_url_filter_event_processor.dart | 6 +- .../connectivity/connectivity_provider.dart | 1 - .../html_connectivity_provider.dart | 33 ------ .../web_connectivity_provider.dart | 2 - .../lib/src/integrations/sdk_integration.dart | 1 - flutter/lib/src/native/factory.dart | 4 +- flutter/lib/src/renderer/html_renderer.dart | 13 --- flutter/lib/src/renderer/renderer.dart | 1 - .../lib/src/web/html_sentry_js_binding.dart | 63 ----------- .../script_loader/html_script_dom_api.dart | 86 --------------- .../src/web/script_loader/script_dom_api.dart | 1 - .../web/script_loader/web_script_dom_api.dart | 3 - flutter/pubspec.yaml | 1 + flutter/test/web/html_utils.dart | 10 -- flutter/test/web/utils.dart | 24 +++- flutter/test/web/web_utils.dart | 26 ----- hive/lib/src/sentry_box_collection.dart | 15 +-- hive/test/mocks/mocks.dart | 6 +- min_version_test/lib/main.dart | 56 +++++----- scripts/publish_validation/README.md | 3 - .../publish_validation/analysis_options.yaml | 1 - .../bin/publish_validation.dart | 63 ----------- scripts/publish_validation/pubspec.yaml | 13 --- 44 files changed, 71 insertions(+), 604 deletions(-) delete mode 100644 dart/lib/src/event_processor/enricher/html_enricher_event_processor.dart delete mode 100644 dart/lib/src/origin_html.dart delete mode 100644 dart/lib/src/platform/_html_platform.dart delete mode 100644 flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart delete mode 100644 flutter/lib/src/integrations/connectivity/html_connectivity_provider.dart delete mode 100644 flutter/lib/src/renderer/html_renderer.dart delete mode 100644 flutter/lib/src/web/html_sentry_js_binding.dart delete mode 100644 flutter/lib/src/web/script_loader/html_script_dom_api.dart delete mode 100644 flutter/test/web/html_utils.dart delete mode 100644 flutter/test/web/web_utils.dart delete mode 100644 scripts/publish_validation/README.md delete mode 100644 scripts/publish_validation/analysis_options.yaml delete mode 100644 scripts/publish_validation/bin/publish_validation.dart delete mode 100644 scripts/publish_validation/pubspec.yaml diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 8ffee32ffb..8d6445d482 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -51,11 +51,6 @@ jobs: - run: dart doc --dry-run - - name: Run publish validation - run: | - dart pub get --directory ../scripts/publish_validation - dart run ../scripts/publish_validation/bin/publish_validation.dart --executable ${{ inputs.sdk }} - package-analysis: # `axel-op/dart-package-analyzer` is using `flutter pub upgrade` instead of `get`, # which ignores pubspec.yaml `dependency_overrides`. Because of that, all `release/*` branches are failing, diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3004ccb6..22a349f92f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Remove `options.autoAppStart` and `setAppStartEnd` ([#2680](https://github.com/getsentry/sentry-dart/pull/2680)) - Add hint for transactions ([#2675](https://github.com/getsentry/sentry-dart/pull/2675)) - `BeforeSendTransactionCallback` now has a `Hint` parameter +- Remove `dart:html` usage in favour of `package:web` ([#2710](https://github.com/getsentry/sentry-dart/pull/2710)) ### Enhancements diff --git a/dart/example_web/pubspec.yaml b/dart/example_web/pubspec.yaml index 8f0d0a8739..5001acbef0 100644 --- a/dart/example_web/pubspec.yaml +++ b/dart/example_web/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: sentry: path: ../../dart/ - web: ^0.5.1 + web: ^1.1.0 dev_dependencies: build_runner: ^2.4.2 diff --git a/dart/lib/src/dart_exception_type_identifier.dart b/dart/lib/src/dart_exception_type_identifier.dart index 59fa6b3db6..9f165ccba4 100644 --- a/dart/lib/src/dart_exception_type_identifier.dart +++ b/dart/lib/src/dart_exception_type_identifier.dart @@ -4,7 +4,6 @@ import 'package:http/http.dart' show ClientException; import '../sentry.dart'; import 'dart_exception_type_identifier_io.dart' - if (dart.library.html) 'dart_exception_type_identifier_web.dart' if (dart.library.js_interop) 'dart_exception_type_identifier_web.dart'; class DartExceptionTypeIdentifier implements ExceptionTypeIdentifier { diff --git a/dart/lib/src/environment/environment_variables.dart b/dart/lib/src/environment/environment_variables.dart index 3dcb1674b3..7efbd877a6 100644 --- a/dart/lib/src/environment/environment_variables.dart +++ b/dart/lib/src/environment/environment_variables.dart @@ -1,6 +1,5 @@ import '../platform_checker.dart'; import '_io_environment_variables.dart' - if (dart.library.html) '_web_environment_variables.dart' if (dart.library.js_interop) '_web_environment_variables.dart' as env; /// Reads environment variables from the system. diff --git a/dart/lib/src/event_processor/enricher/enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/enricher_event_processor.dart index 779d64b700..2b42b8f043 100644 --- a/dart/lib/src/event_processor/enricher/enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/enricher_event_processor.dart @@ -1,7 +1,6 @@ import '../../event_processor.dart'; import '../../sentry_options.dart'; import 'io_enricher_event_processor.dart' - if (dart.library.html) 'html_enricher_event_processor.dart' if (dart.library.js_interop) 'web_enricher_event_processor.dart'; abstract class EnricherEventProcessor implements EventProcessor { diff --git a/dart/lib/src/event_processor/enricher/html_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/html_enricher_event_processor.dart deleted file mode 100644 index b988c7d14b..0000000000 --- a/dart/lib/src/event_processor/enricher/html_enricher_event_processor.dart +++ /dev/null @@ -1,104 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:html' as html show window, Window; - -import '../../../sentry.dart'; -import 'enricher_event_processor.dart'; - -EnricherEventProcessor enricherEventProcessor(SentryOptions options) { - return WebEnricherEventProcessor( - html.window, - options, - ); -} - -class WebEnricherEventProcessor implements EnricherEventProcessor { - WebEnricherEventProcessor( - this._window, - this._options, - ); - - final html.Window _window; - - final SentryOptions _options; - - @override - SentryEvent? apply(SentryEvent event, Hint hint) { - // Web has no native integration, so no need to check for it - - final contexts = event.contexts.copyWith( - device: _getDevice(event.contexts.device), - culture: _getSentryCulture(event.contexts.culture), - ); - - contexts['dart_context'] = _getDartContext(); - - return event.copyWith( - contexts: contexts, - request: _getRequest(event.request), - transaction: event.transaction ?? _window.location.pathname, - ); - } - - // As seen in - // https://github.com/getsentry/sentry-javascript/blob/a6f8dc26a4c7ae2146ae64995a2018c8578896a6/packages/browser/src/integrations/useragent.ts - SentryRequest _getRequest(SentryRequest? request) { - final requestHeader = request?.headers; - final header = requestHeader == null - ? {} - : Map.from(requestHeader); - - header.putIfAbsent('User-Agent', () => _window.navigator.userAgent); - - final url = request?.url ?? _window.location.toString(); - return (request ?? SentryRequest(url: url)) - .copyWith(headers: header) - .sanitized(); - } - - SentryDevice _getDevice(SentryDevice? device) { - return (device ?? SentryDevice()).copyWith( - online: device?.online ?? _window.navigator.onLine, - memorySize: device?.memorySize ?? _getMemorySize(), - orientation: device?.orientation ?? _getScreenOrientation(), - screenHeightPixels: device?.screenHeightPixels ?? - _window.screen?.available.height.toInt(), - screenWidthPixels: - device?.screenWidthPixels ?? _window.screen?.available.width.toInt(), - screenDensity: - device?.screenDensity ?? _window.devicePixelRatio.toDouble(), - ); - } - - int? _getMemorySize() { - // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/deviceMemory - final size = _window.navigator.deviceMemory?.toDouble(); - final memoryByteSize = size != null ? size * 1024 * 1024 * 1024 : null; - return memoryByteSize?.toInt(); - } - - SentryOrientation? _getScreenOrientation() { - // https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation - final screenOrientation = _window.screen?.orientation; - if (screenOrientation != null) { - if (screenOrientation.type?.startsWith('portrait') ?? false) { - return SentryOrientation.portrait; - } - if (screenOrientation.type?.startsWith('landscape') ?? false) { - return SentryOrientation.landscape; - } - } - return null; - } - - Map _getDartContext() { - return { - 'compile_mode': _options.platformChecker.compileMode, - }; - } - - SentryCulture _getSentryCulture(SentryCulture? culture) { - return (culture ?? SentryCulture()).copyWith( - timezone: culture?.timezone ?? DateTime.now().timeZoneName, - ); - } -} diff --git a/dart/lib/src/event_processor/enricher/web_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/web_enricher_event_processor.dart index 27bb6b99db..c3dfd47c71 100644 --- a/dart/lib/src/event_processor/enricher/web_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/web_enricher_event_processor.dart @@ -1,5 +1,3 @@ -// We would lose compatibility with old dart versions by adding web to pubspec. -// ignore: depend_on_referenced_packages import 'package:web/web.dart' as web show window, Window, Navigator; import '../../../sentry.dart'; diff --git a/dart/lib/src/event_processor/exception/exception_event_processor.dart b/dart/lib/src/event_processor/exception/exception_event_processor.dart index ab4f5e9878..6e65c72391 100644 --- a/dart/lib/src/event_processor/exception/exception_event_processor.dart +++ b/dart/lib/src/event_processor/exception/exception_event_processor.dart @@ -1,7 +1,6 @@ import '../../event_processor.dart'; import '../../sentry_options.dart'; import 'io_exception_event_processor.dart' - if (dart.library.html) 'web_exception_event_processor.dart' if (dart.library.js_interop) 'web_exception_event_processor.dart'; abstract class ExceptionEventProcessor implements EventProcessor { diff --git a/dart/lib/src/origin.dart b/dart/lib/src/origin.dart index 1d5b3dc4bf..65835e7e0a 100644 --- a/dart/lib/src/origin.dart +++ b/dart/lib/src/origin.dart @@ -1,3 +1 @@ -export 'origin_io.dart' - if (dart.library.html) 'origin_html.dart' - if (dart.library.js_interop) 'origin_web.dart'; +export 'origin_io.dart' if (dart.library.js_interop) 'origin_web.dart'; diff --git a/dart/lib/src/origin_html.dart b/dart/lib/src/origin_html.dart deleted file mode 100644 index 43a6a18b11..0000000000 --- a/dart/lib/src/origin_html.dart +++ /dev/null @@ -1,5 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:html'; - -/// request origin, used for browser stacktrace -String get eventOrigin => '${window.location.origin}/'; diff --git a/dart/lib/src/origin_web.dart b/dart/lib/src/origin_web.dart index db99f33c56..0653054b7a 100644 --- a/dart/lib/src/origin_web.dart +++ b/dart/lib/src/origin_web.dart @@ -1,5 +1,3 @@ -// We would lose compatibility with old dart versions by adding web to pubspec. -// ignore: depend_on_referenced_packages import 'package:web/web.dart'; /// request origin, used for browser stacktrace diff --git a/dart/lib/src/platform/_html_platform.dart b/dart/lib/src/platform/_html_platform.dart deleted file mode 100644 index ea9b388e52..0000000000 --- a/dart/lib/src/platform/_html_platform.dart +++ /dev/null @@ -1,53 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:html' as html; - -import 'platform.dart'; - -const Platform instance = WebPlatform(); - -/// [Platform] implementation that delegates to `dart:html`. -class WebPlatform extends Platform { - /// Creates a new [Platform]. - const WebPlatform(); - - @override - String get operatingSystem => _browserPlatform(); - - @override - String get operatingSystemVersion => 'unknown'; - - @override - String get localHostname => html.window.location.hostname ?? 'unknown'; - - String _browserPlatform() { - final navigatorPlatform = - html.window.navigator.platform?.toLowerCase() ?? ''; - if (navigatorPlatform.startsWith('mac')) { - return 'macos'; - } - if (navigatorPlatform.startsWith('win')) { - return 'windows'; - } - if (navigatorPlatform.contains('iphone') || - navigatorPlatform.contains('ipad') || - navigatorPlatform.contains('ipod')) { - return 'ios'; - } - if (navigatorPlatform.contains('android')) { - return 'android'; - } - if (navigatorPlatform.contains('fuchsia')) { - return 'fuchsia'; - } - - // Since some phones can report a window.navigator.platform as Linux, fall - // back to use CSS to disambiguate Android vs Linux desktop. If the CSS - // indicates that a device has a "fine pointer" (mouse) as the primary - // pointing device, then we'll assume desktop linux, and otherwise we'll - // assume Android. - if (html.window.matchMedia('only screen and (pointer: fine)').matches) { - return 'linux'; - } - return 'android'; - } -} diff --git a/dart/lib/src/platform/_web_platform.dart b/dart/lib/src/platform/_web_platform.dart index da403b254d..97c05815be 100644 --- a/dart/lib/src/platform/_web_platform.dart +++ b/dart/lib/src/platform/_web_platform.dart @@ -1,5 +1,3 @@ -// We would lose compatibility with old dart versions by adding web to pubspec. -// ignore: depend_on_referenced_packages import 'package:web/web.dart' as web; import 'platform.dart'; diff --git a/dart/lib/src/platform/platform.dart b/dart/lib/src/platform/platform.dart index ab2f94dd5f..e3d5ae9f32 100644 --- a/dart/lib/src/platform/platform.dart +++ b/dart/lib/src/platform/platform.dart @@ -1,8 +1,7 @@ import 'dart:typed_data'; -import '_io_platform.dart' - if (dart.library.html) '_html_platform.dart' - if (dart.library.js_interop) '_web_platform.dart' as platform; +import '_io_platform.dart' if (dart.library.js_interop) '_web_platform.dart' + as platform; const Platform instance = platform.instance; diff --git a/dart/lib/src/utils/isolate_utils.dart b/dart/lib/src/utils/isolate_utils.dart index 6575965ff9..0db3332677 100644 --- a/dart/lib/src/utils/isolate_utils.dart +++ b/dart/lib/src/utils/isolate_utils.dart @@ -1,7 +1,6 @@ import 'package:meta/meta.dart'; import '_io_get_isolate_name.dart' - if (dart.library.html) '_web_get_isolate_name.dart' if (dart.library.js_interop) '_web_get_isolate_name.dart' as isolate_getter; @internal diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml index 562de17c7e..c87c4d0f88 100644 --- a/dart/pubspec.yaml +++ b/dart/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: stack_trace: ^1.10.0 uuid: '>=3.0.0 <5.0.0' collection: ^1.16.0 + web: ^1.1.0 dev_dependencies: build_runner: ^2.3.0 diff --git a/dart/test/event_processor/enricher/web_enricher_test.dart b/dart/test/event_processor/enricher/web_enricher_test.dart index dbf2457452..ae27ecc392 100644 --- a/dart/test/event_processor/enricher/web_enricher_test.dart +++ b/dart/test/event_processor/enricher/web_enricher_test.dart @@ -2,9 +2,7 @@ library; import 'package:sentry/sentry.dart'; -import 'package:sentry/src/event_processor/enricher/html_enricher_event_processor.dart' - if (dart.library.html) 'package:sentry/src/event_processor/enricher/html_enricher_event_processor.dart' - if (dart.library.js_interop) 'package:sentry/src/event_processor/enricher/web_enricher_event_processor.dart'; +import 'package:sentry/src/event_processor/enricher/web_enricher_event_processor.dart'; import 'package:test/test.dart'; import '../../mocks.dart'; diff --git a/file/lib/src/sentry_file_extension.dart b/file/lib/src/sentry_file_extension.dart index 3cc764c36e..2ddb327605 100644 --- a/file/lib/src/sentry_file_extension.dart +++ b/file/lib/src/sentry_file_extension.dart @@ -1,8 +1,6 @@ // ignore_for_file: invalid_use_of_internal_member -import 'dart:io' - if (dart.library.html) 'dart:html' - if (dart.library.js_interop) 'dart:js_interop'; +import 'dart:io' if (dart.library.js_interop) 'dart:js_interop'; import 'package:meta/meta.dart'; import 'package:sentry/sentry.dart'; @@ -29,9 +27,7 @@ extension SentryFileExtension on File { /// /// All the copy, create, delete, open, rename, read, and write operations are /// supported. - File sentryTrace({ - @internal Hub? hub, - }) { + File sentryTrace({@internal Hub? hub}) { final _hub = hub ?? HubAdapter(); if (_hub.options.platformChecker.isWeb || diff --git a/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart b/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart deleted file mode 100644 index acd00daeb9..0000000000 --- a/flutter/lib/src/event_processor/url_filter/html_url_filter_event_processor.dart +++ /dev/null @@ -1,39 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:html' as html show window, Window; - -// ignore: implementation_imports -import 'package:sentry/src/utils/regex_utils.dart'; - -import '../../../sentry_flutter.dart'; -import 'url_filter_event_processor.dart'; - -// ignore_for_file: invalid_use_of_internal_member - -UrlFilterEventProcessor urlFilterEventProcessor(SentryFlutterOptions options) => - WebUrlFilterEventProcessor(options); - -class WebUrlFilterEventProcessor implements UrlFilterEventProcessor { - WebUrlFilterEventProcessor( - this._options, - ); - - final html.Window _window = html.window; - final SentryFlutterOptions _options; - - @override - SentryEvent? apply(SentryEvent event, Hint hint) { - final url = _window.location.toString(); - - if (_options.allowUrls.isNotEmpty && - !isMatchingRegexPattern(url, _options.allowUrls)) { - return null; - } - - if (_options.denyUrls.isNotEmpty && - isMatchingRegexPattern(url, _options.denyUrls)) { - return null; - } - - return event; - } -} diff --git a/flutter/lib/src/event_processor/url_filter/url_filter_event_processor.dart b/flutter/lib/src/event_processor/url_filter/url_filter_event_processor.dart index 5a1e5ed537..170507d5e9 100644 --- a/flutter/lib/src/event_processor/url_filter/url_filter_event_processor.dart +++ b/flutter/lib/src/event_processor/url_filter/url_filter_event_processor.dart @@ -1,6 +1,5 @@ import '../../../sentry_flutter.dart'; import 'io_url_filter_event_processor.dart' - if (dart.library.html) 'html_url_filter_event_processor.dart' if (dart.library.js_interop) 'web_url_filter_event_processor.dart'; abstract class UrlFilterEventProcessor implements EventProcessor { diff --git a/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart b/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart index 3b94afeed8..af35a04a7d 100644 --- a/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart +++ b/flutter/lib/src/event_processor/url_filter/web_url_filter_event_processor.dart @@ -1,11 +1,9 @@ -// We would lose compatibility with old dart versions by adding web to pubspec. -// ignore: depend_on_referenced_packages +// ignore: implementation_imports +import 'package:sentry/src/utils/regex_utils.dart'; import 'package:web/web.dart' as web show window, Window; import '../../../sentry_flutter.dart'; import 'url_filter_event_processor.dart'; -// ignore: implementation_imports -import 'package:sentry/src/utils/regex_utils.dart'; // ignore_for_file: invalid_use_of_internal_member diff --git a/flutter/lib/src/integrations/connectivity/connectivity_provider.dart b/flutter/lib/src/integrations/connectivity/connectivity_provider.dart index ea27f80f72..3ee2690627 100644 --- a/flutter/lib/src/integrations/connectivity/connectivity_provider.dart +++ b/flutter/lib/src/integrations/connectivity/connectivity_provider.dart @@ -1,5 +1,4 @@ import 'noop_connectivity_provider.dart' - if (dart.library.html) 'html_connectivity_provider.dart' if (dart.library.js_interop) 'web_connectivity_provider.dart'; abstract class ConnectivityProvider { diff --git a/flutter/lib/src/integrations/connectivity/html_connectivity_provider.dart b/flutter/lib/src/integrations/connectivity/html_connectivity_provider.dart deleted file mode 100644 index 1b30376aaf..0000000000 --- a/flutter/lib/src/integrations/connectivity/html_connectivity_provider.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'dart:async'; -// ignore: deprecated_member_use -import 'dart:html' as html; - -import 'connectivity_provider.dart'; - -ConnectivityProvider connectivityProvider() { - return WebConnectivityProvider(); -} - -class WebConnectivityProvider implements ConnectivityProvider { - StreamSubscription? _onOnlineSub; - StreamSubscription? _onOfflineSub; - - @override - void listen(void Function(String connectivity) onChange) { - _onOnlineSub = html.window.onOnline.listen((_) { - onChange('wifi'); - }); - _onOfflineSub = html.window.onOffline.listen((_) { - onChange('none'); - }); - } - - @override - void cancel() { - _onOnlineSub?.cancel(); - _onOnlineSub = null; - - _onOfflineSub?.cancel(); - _onOfflineSub = null; - } -} diff --git a/flutter/lib/src/integrations/connectivity/web_connectivity_provider.dart b/flutter/lib/src/integrations/connectivity/web_connectivity_provider.dart index d1c18af777..19d2bc6da6 100644 --- a/flutter/lib/src/integrations/connectivity/web_connectivity_provider.dart +++ b/flutter/lib/src/integrations/connectivity/web_connectivity_provider.dart @@ -1,7 +1,5 @@ import 'dart:async'; -// We would lose compatibility with old dart versions by adding web to pubspec. -// ignore: depend_on_referenced_packages import 'package:web/web.dart' as web; import 'connectivity_provider.dart'; diff --git a/flutter/lib/src/integrations/sdk_integration.dart b/flutter/lib/src/integrations/sdk_integration.dart index c0ca43dc0d..6ed156ad94 100644 --- a/flutter/lib/src/integrations/sdk_integration.dart +++ b/flutter/lib/src/integrations/sdk_integration.dart @@ -1,3 +1,2 @@ export 'native_sdk_integration.dart' - if (dart.library.html) 'web_sdk_integration.dart' if (dart.library.js_interop) 'web_sdk_integration.dart'; diff --git a/flutter/lib/src/native/factory.dart b/flutter/lib/src/native/factory.dart index c81c526594..e45ab999f7 100644 --- a/flutter/lib/src/native/factory.dart +++ b/flutter/lib/src/native/factory.dart @@ -1,3 +1 @@ -export 'factory_real.dart' - if (dart.library.html) 'factory_web.dart' - if (dart.library.js_interop) 'factory_web.dart'; +export 'factory_real.dart' if (dart.library.js_interop) 'factory_web.dart'; diff --git a/flutter/lib/src/renderer/html_renderer.dart b/flutter/lib/src/renderer/html_renderer.dart deleted file mode 100644 index 91d10ae2da..0000000000 --- a/flutter/lib/src/renderer/html_renderer.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:js' as js; - -import 'renderer.dart'; - -FlutterRenderer? getRenderer() { - return isCanvasKitRenderer ? FlutterRenderer.canvasKit : FlutterRenderer.html; -} - -bool get isCanvasKitRenderer { - final flutterCanvasKit = js.context['flutterCanvasKit']; - return flutterCanvasKit != null; -} diff --git a/flutter/lib/src/renderer/renderer.dart b/flutter/lib/src/renderer/renderer.dart index dc9d81276b..42db6e9bf6 100644 --- a/flutter/lib/src/renderer/renderer.dart +++ b/flutter/lib/src/renderer/renderer.dart @@ -1,7 +1,6 @@ import 'package:meta/meta.dart'; import 'unknown_renderer.dart' - if (dart.library.html) 'html_renderer.dart' if (dart.library.js_interop) 'web_renderer.dart' if (dart.library.io) 'io_renderer.dart' as implementation; diff --git a/flutter/lib/src/web/html_sentry_js_binding.dart b/flutter/lib/src/web/html_sentry_js_binding.dart deleted file mode 100644 index 872ea83e82..0000000000 --- a/flutter/lib/src/web/html_sentry_js_binding.dart +++ /dev/null @@ -1,63 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:js'; - -import 'package:flutter/cupertino.dart'; - -import 'sentry_js_binding.dart'; - -SentryJsBinding createJsBinding() { - return HtmlSentryJsBinding(); -} - -class HtmlSentryJsBinding implements SentryJsBinding { - HtmlSentryJsBinding({JsObject? sentry}) : _sentry = sentry; - - JsObject? _sentry; - dynamic _client; - - @override - void init(Map options) { - if (options['defaultIntegrations'] != null) { - options['defaultIntegrations'] = options['defaultIntegrations'] - .map((String integration) => _createIntegration(integration)); - } - - _sentry ??= context['Sentry'] as JsObject; - _sentry!.callMethod('init', [JsObject.jsify(options)]); - _client = _sentry!.callMethod('getClient'); - } - - JsObject? _createIntegration(String integration) { - switch (integration) { - case SentryJsIntegrationName.globalHandlers: - case SentryJsIntegrationName.dedupe: - final jsIntegration = _sentry?.callMethod(integration, []); - return jsIntegration is JsObject ? jsIntegration : null; - default: - return null; - } - } - - @override - void close() { - if (_sentry != null) { - _sentry?.callMethod('close'); - _sentry = null; - context['Sentry'] = null; - } - } - - @override - void captureEnvelope(List envelope) { - if (_client != null) { - _client.callMethod('sendEnvelope', [JsObject.jsify(envelope)]); - } - } - - @visibleForTesting - @override - getJsOptions() { - final sentry = context['Sentry'] as JsObject; - return sentry.callMethod('getClient').callMethod('getOptions').dartify(); - } -} diff --git a/flutter/lib/src/web/script_loader/html_script_dom_api.dart b/flutter/lib/src/web/script_loader/html_script_dom_api.dart deleted file mode 100644 index 233376eae3..0000000000 --- a/flutter/lib/src/web/script_loader/html_script_dom_api.dart +++ /dev/null @@ -1,86 +0,0 @@ -import 'dart:async'; -// ignore: deprecated_member_use -import 'dart:html'; -// ignore: deprecated_member_use -import 'dart:js_util' as js_util; - -import '../../../sentry_flutter.dart'; -import 'script_dom_api.dart'; -import 'sentry_script_loader.dart'; - -Future loadScript(String src, SentryOptions options, - {String? integrity, - String trustedTypePolicyName = defaultTrustedPolicyName}) { - final completer = Completer(); - - final script = ScriptElement() - ..crossOrigin = 'anonymous' - ..onLoad.listen((_) => completer.complete()) - ..onError.listen((event) => completer.completeError('Failed to load $src')); - - TrustedScriptUrl? trustedUrl; - - // If TrustedTypes are available, prepare a trusted URL - final trustedTypes = js_util.getProperty(window, 'trustedTypes'); - if (trustedTypes != null) { - try { - final policy = - js_util.callMethod(trustedTypes as Object, 'createPolicy', [ - trustedTypePolicyName, - js_util.jsify({ - 'createScriptURL': (String url) => src, - }) - ]); - trustedUrl = - js_util.callMethod(policy as Object, 'createScriptURL', [src]); - } catch (e) { - // will be caught by loadWebSdk - throw TrustedTypesException(); - } - } - - if (trustedUrl != null) { - js_util.setProperty(script, 'src', trustedUrl); - } else { - script.src = src; - } - - if (integrity != null) { - script.integrity = integrity; - } - - // JS SDK needs to be loaded before everything else - final head = document.head; - if (head != null) { - if (head.hasChildNodes()) { - head.insertBefore(script, head.firstChild); - } else { - head.append(script); - } - } - return completer.future; -} - -class _ScriptElement implements SentryScriptElement { - final ScriptElement element; - - _ScriptElement(this.element); - - @override - void remove() { - element.remove(); - } - - @override - String get src => element.src; - - @override - String? get integrity => element.integrity; -} - -List fetchScripts(String query) { - final scripts = document.querySelectorAll(query); - return scripts - .map((script) => _ScriptElement(script as ScriptElement)) - .toList(); -} diff --git a/flutter/lib/src/web/script_loader/script_dom_api.dart b/flutter/lib/src/web/script_loader/script_dom_api.dart index bca967d4d3..db557f5b3f 100644 --- a/flutter/lib/src/web/script_loader/script_dom_api.dart +++ b/flutter/lib/src/web/script_loader/script_dom_api.dart @@ -1,7 +1,6 @@ import 'package:meta/meta.dart'; export 'noop_script_dom_api.dart' - if (dart.library.html) 'html_script_dom_api.dart' if (dart.library.js_interop) 'web_script_dom_api.dart'; @internal diff --git a/flutter/lib/src/web/script_loader/web_script_dom_api.dart b/flutter/lib/src/web/script_loader/web_script_dom_api.dart index ef02adabe1..dba089b2ba 100644 --- a/flutter/lib/src/web/script_loader/web_script_dom_api.dart +++ b/flutter/lib/src/web/script_loader/web_script_dom_api.dart @@ -1,10 +1,7 @@ import 'dart:async'; import 'dart:js_interop'; import 'dart:js_interop_unsafe'; - -// ignore: depend_on_referenced_packages import 'package:web/web.dart'; - import '../../../sentry_flutter.dart'; import 'script_dom_api.dart'; import 'sentry_script_loader.dart'; diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index ca7f42fd9f..c311d7c2a6 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: meta: ^1.3.0 ffi: ^2.0.0 collection: ^1.16.0 + web: ^1.1.0 jni: 0.14.0 dev_dependencies: diff --git a/flutter/test/web/html_utils.dart b/flutter/test/web/html_utils.dart deleted file mode 100644 index 9d1557a668..0000000000 --- a/flutter/test/web/html_utils.dart +++ /dev/null @@ -1,10 +0,0 @@ -// ignore: deprecated_member_use -import 'dart:html'; - -void injectMetaTag(Map attributes) { - final MetaElement meta = document.createElement('meta') as MetaElement; - for (final MapEntry attribute in attributes.entries) { - meta.setAttribute(attribute.key, attribute.value); - } - document.head!.append(meta); -} diff --git a/flutter/test/web/utils.dart b/flutter/test/web/utils.dart index 81fc6af0c7..bd8481ed26 100644 --- a/flutter/test/web/utils.dart +++ b/flutter/test/web/utils.dart @@ -1,6 +1,28 @@ +import 'dart:js_interop'; +import 'dart:js_interop_unsafe'; import 'package:sentry_flutter/src/web/script_loader/script_dom_api.dart'; +import 'package:web/web.dart'; -export 'html_utils.dart' if (dart.library.js_interop) 'web_utils.dart'; +void injectMetaTag(Map attributes) { + final HTMLMetaElement meta = + document.createElement('meta') as HTMLMetaElement; + for (final MapEntry attribute in attributes.entries) { + meta.setAttribute(attribute.key, attribute.value); + } + document.head!.appendChild(meta); +} + +@JS('Sentry') +external JSObject? get sentry; + +dynamic getJsOptions() { + final client = sentry?.callMethod('getClient'.toJS, null) as JSObject?; + if (client == null) { + return null; + } + final options = client.callMethod('getOptions'.toJS, null); + return options?.dartify(); +} List fetchAllScripts() { return fetchScripts('script'); diff --git a/flutter/test/web/web_utils.dart b/flutter/test/web/web_utils.dart deleted file mode 100644 index 53ec33f6b3..0000000000 --- a/flutter/test/web/web_utils.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'dart:js_interop'; -import 'dart:js_interop_unsafe'; - -// ignore: depend_on_referenced_packages -import 'package:web/web.dart'; - -void injectMetaTag(Map attributes) { - final HTMLMetaElement meta = - document.createElement('meta') as HTMLMetaElement; - for (final MapEntry attribute in attributes.entries) { - meta.setAttribute(attribute.key, attribute.value); - } - document.head!.appendChild(meta); -} - -@JS('Sentry') -external JSObject? get sentry; - -dynamic getJsOptions() { - final client = sentry?.callMethod('getClient'.toJS, null) as JSObject?; - if (client == null) { - return null; - } - final options = client.callMethod('getOptions'.toJS, null); - return options?.dartify(); -} diff --git a/hive/lib/src/sentry_box_collection.dart b/hive/lib/src/sentry_box_collection.dart index 0dee9e9831..48f28f60f1 100644 --- a/hive/lib/src/sentry_box_collection.dart +++ b/hive/lib/src/sentry_box_collection.dart @@ -1,18 +1,15 @@ import 'package:hive/hive.dart'; -import 'package:meta/meta.dart'; -import 'package:sentry/sentry.dart'; - -import 'sentry_span_helper.dart'; - -// ignore: implementation_imports -import 'package:hive/src/box_collection/box_collection_stub.dart' as stub; - // ignore: implementation_imports import 'package:hive/src/box_collection/box_collection_stub.dart' - if (dart.library.html) 'package:hive/src/box_collection/box_collection_indexed_db.dart' if (dart.library.js_interop) 'package:hive/src/box_collection/box_collection_indexed_db.dart' if (dart.library.io) 'package:hive/src/box_collection/box_collection.dart' as impl; +// ignore: implementation_imports +import 'package:hive/src/box_collection/box_collection_stub.dart' as stub; +import 'package:meta/meta.dart'; +import 'package:sentry/sentry.dart'; + +import 'sentry_span_helper.dart'; /// Use instead of [BoxCollection] to add automatic tracing. class SentryBoxCollection implements stub.BoxCollection { diff --git a/hive/test/mocks/mocks.dart b/hive/test/mocks/mocks.dart index 8b6d7f4db9..5853473cac 100644 --- a/hive/test/mocks/mocks.dart +++ b/hive/test/mocks/mocks.dart @@ -1,12 +1,10 @@ import 'package:hive/hive.dart'; -import 'package:mockito/annotations.dart'; -import 'package:sentry/sentry.dart'; - import 'package:hive/src/box_collection/box_collection_stub.dart' - if (dart.library.html) 'package:hive/src/box_collection/box_collection_indexed_db.dart' if (dart.library.js_interop) 'package:hive/src/box_collection/box_collection_indexed_db.dart' if (dart.library.io) 'package:hive/src/box_collection/box_collection.dart' as impl; +import 'package:mockito/annotations.dart'; +import 'package:sentry/sentry.dart'; @GenerateMocks([ Hub, diff --git a/min_version_test/lib/main.dart b/min_version_test/lib/main.dart index e1f182197a..9900260666 100644 --- a/min_version_test/lib/main.dart +++ b/min_version_test/lib/main.dart @@ -1,7 +1,5 @@ import 'package:flutter/material.dart'; - import 'package:min_version_test/transaction/transaction_stub.dart' - if (dart.library.html) 'package:min_version_test/transaction/web_transaction.dart' if (dart.library.js_interop) 'package:min_version_test/transaction/web_transaction.dart' if (dart.library.io) 'package:min_version_test/transaction/file_transaction.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; @@ -12,32 +10,33 @@ const String _exampleDsn = 'https://e85b375ffb9f43cf8bdf9787768149e0@o447951.ingest.sentry.io/5428562'; Future main() async { - await setupSentry(() => runApp( - DefaultAssetBundle( - bundle: SentryAssetBundle(), - child: const MyApp(), - ), - )); + await setupSentry( + () => runApp( + DefaultAssetBundle(bundle: SentryAssetBundle(), child: const MyApp()), + ), + ); } Future setupSentry(AppRunner appRunner) async { - await SentryFlutter.init((options) { - options.dsn = _exampleDsn; - options.tracesSampleRate = 1.0; - options.attachThreads = true; - options.enableWindowMetricBreadcrumbs = true; - options.addIntegration(LoggingIntegration()); - options.sendDefaultPii = true; - options.reportSilentFlutterErrors = true; - options.attachScreenshot = true; - options.attachViewHierarchy = true; - // We can enable Sentry debug logging during development. This is likely - // going to log too much for your app, but can be useful when figuring out - // configuration issues, e.g. finding out why your events are not uploaded. - options.debug = true; - }, - // Init your App. - appRunner: appRunner); + await SentryFlutter.init( + (options) { + options.dsn = _exampleDsn; + options.tracesSampleRate = 1.0; + options.attachThreads = true; + options.enableWindowMetricBreadcrumbs = true; + options.addIntegration(LoggingIntegration()); + options.sendDefaultPii = true; + options.reportSilentFlutterErrors = true; + options.attachScreenshot = true; + options.attachViewHierarchy = true; + // We can enable Sentry debug logging during development. This is likely + // going to log too much for your app, but can be useful when figuring out + // configuration issues, e.g. finding out why your events are not uploaded. + options.debug = true; + }, + // Init your App. + appRunner: appRunner, + ); } class MyApp extends StatelessWidget { @@ -61,7 +60,8 @@ class MyApp extends StatelessWidget { primarySwatch: Colors.blue, ), home: SentryWidget( - child: const MyHomePage(title: 'Flutter Demo Home Page')), + child: const MyHomePage(title: 'Flutter Demo Home Page'), + ), ); } } @@ -135,9 +135,7 @@ class _MyHomePageState extends State { // horizontal). mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( - 'You have pushed the button this many times:', - ), + const Text('You have pushed the button this many times:'), Text( '$_counter', // ignore: deprecated_member_use diff --git a/scripts/publish_validation/README.md b/scripts/publish_validation/README.md deleted file mode 100644 index e87d94c86d..0000000000 --- a/scripts/publish_validation/README.md +++ /dev/null @@ -1,3 +0,0 @@ -An internal command-line application to validate publish. -We temporarily need to use the `--skip-validation` flag in order to publish with backwards compatible WASM support. -Since we now don't have validations in place, this validation tool will catch unexpected errors that might occur during dry runs. \ No newline at end of file diff --git a/scripts/publish_validation/analysis_options.yaml b/scripts/publish_validation/analysis_options.yaml deleted file mode 100644 index 572dd239d0..0000000000 --- a/scripts/publish_validation/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: package:lints/recommended.yaml diff --git a/scripts/publish_validation/bin/publish_validation.dart b/scripts/publish_validation/bin/publish_validation.dart deleted file mode 100644 index fd8a93aef8..0000000000 --- a/scripts/publish_validation/bin/publish_validation.dart +++ /dev/null @@ -1,63 +0,0 @@ -import 'dart:io'; - -import 'package:args/args.dart'; - -void main(List arguments) async { - final parser = ArgParser() - ..addOption( - 'executable', - allowed: ['dart', 'flutter'], - defaultsTo: 'dart', - help: 'Specify the executable to use (dart or flutter)', - ); - - ArgResults args; - try { - args = parser.parse(arguments); - } on FormatException catch (e) { - print('Error: ${e.message}'); - print('Usage: dart script.dart [--executable ]'); - exit(1); - } - - final executable = args['executable'] as String; - - final result = await Process.run(executable, ['pub', 'publish', '--dry-run']); - final publishOutput = result.stderr as String; - - if (publishOutput.contains('Found no `pubspec.yaml` file')) { - print(publishOutput); - exit(1); - } - - const expectedErrors = [ - 'lib/src/integrations/connectivity/web_connectivity_provider.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', - 'lib/src/event_processor/enricher/web_enricher_event_processor.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', - 'lib/src/origin_web.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', - 'lib/src/platform/_web_platform.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', - 'lib/src/event_processor/url_filter/web_url_filter_event_processor.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', - 'lib/src/web/script_loader/web_script_dom_api.dart: This package does not have web in the `dependencies` section of `pubspec.yaml`', - 'test/web/dom_api/web_script_dom_api.dart: This package does not have web in the `dependencies` or `dev_dependencies` section of `pubspec.yaml`', - 'test/web/web_utils.dart: This package does not have web in the `dependencies` or `dev_dependencies` section of `pubspec.yaml`', - ]; - - // So far the expected errors all start with `* line` - final errorLines = publishOutput - .split('\n') - .where((line) => line.startsWith('* line')) - .toList(); - - final unexpectedErrors = errorLines.where((errorLine) { - return !expectedErrors - .any((expectedError) => errorLine.contains(expectedError)); - }).toList(); - - if (unexpectedErrors.isEmpty) { - print('Only expected errors found. Validation passed.'); - exit(0); - } else { - print('Unexpected errors found:'); - unexpectedErrors.forEach(print); - exit(1); - } -} diff --git a/scripts/publish_validation/pubspec.yaml b/scripts/publish_validation/pubspec.yaml deleted file mode 100644 index a8dd96a670..0000000000 --- a/scripts/publish_validation/pubspec.yaml +++ /dev/null @@ -1,13 +0,0 @@ -name: publish_validation -description: Command-line application for validating publish dry runs. -publish_to: none - -environment: - sdk: ^3.4.3 - -dependencies: - args: ^2.5.0 - -dev_dependencies: - lints: ^3.0.0 - test: ^1.24.0