Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

- Prefix firebase remote config feature flags with `firebase:` ([#3258](https://github.com/getsentry/sentry-dart/pull/3258))

### Fixes

- Safely access browser `navigator.deviceMemory` ([#3268](https://github.com/getsentry/sentry-dart/pull/3268))

## 9.7.0-beta.5

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:web/web.dart' as web show window, Window, Navigator;
import 'dart:js_interop';

import '../../../sentry.dart';
import 'enricher_event_processor.dart';
Expand Down Expand Up @@ -69,8 +70,7 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {

int? _getMemorySize() {
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/deviceMemory
// ignore: invalid_null_aware_operator
final size = _window.navigator.deviceMemory?.toDouble();
final size = _window.navigator.safeDeviceMemory?.toDouble();
final memoryByteSize = size != null ? size * 1024 * 1024 * 1024 : null;
return memoryByteSize?.toInt();
}
Expand Down Expand Up @@ -116,7 +116,15 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
}
}

extension on web.Navigator {
// ignore: unused_element
external double? get deviceMemory;
/// Some Navigator properties are not fully supported in all browsers.
/// However, package:web does not provide a safe way to access these properties,
/// and assumes they are always not null.
///
/// This extension provides a safe way to access these properties.
///
/// See: https://github.com/dart-lang/web/issues/326
/// https://github.com/fluttercommunity/plus_plugins/issues/3391
extension SafeNavigationGetterExtensions on web.Navigator {
@JS('deviceMemory')
external double? get safeDeviceMemory;
}
Loading