Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
);
```

- Add `screenshotCacheDuration` to `FlutterOptions` ([#2387](https://github.com/getsentry/sentry-dart/pull/2387))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 🚫 The changelog entry seems to be part of an already released section ## 8.10.1.
    Consider moving the entry to the ## Unreleased section, please.

- Screenshots will be cached for 100ms per default.

### Enhancements

- Avoid sending too many empty client reports when Http Transport is used ([#2380](https://github.com/getsentry/sentry-dart/pull/2380))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
class ScreenshotEventProcessor implements EventProcessor {
final SentryFlutterOptions _options;

Uint8List? _cachedScreenshotData;
DateTime? _lastScreenshotTime;

ScreenshotEventProcessor(this._options);

@override
Expand Down Expand Up @@ -77,13 +80,26 @@
return event;
}

final bytes = await createScreenshot();
final bytes = await _getOrCreateScreenshot();
if (bytes != null) {
hint.screenshot = SentryAttachment.fromScreenshotData(bytes);
}
return event;
}

Future<Uint8List?> _getOrCreateScreenshot() async {
if (_options.screenshotCacheDuration.inMilliseconds > 0 &&
_cachedScreenshotData != null &&
_lastScreenshotTime != null &&
DateTime.now().difference(_lastScreenshotTime!) <
_options.screenshotCacheDuration) {
return _cachedScreenshotData;

Check warning on line 96 in flutter/lib/src/event_processor/screenshot_event_processor.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/event_processor/screenshot_event_processor.dart#L93-L96

Added lines #L93 - L96 were not covered by tests
}
_cachedScreenshotData = await createScreenshot();
_lastScreenshotTime = DateTime.now();
return _cachedScreenshotData;
}

@internal
Future<Uint8List?> createScreenshot() async {
try {
Expand Down
4 changes: 4 additions & 0 deletions flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ class SentryFlutterOptions extends SentryOptions {
/// Only attach a screenshot when the app is resumed.
bool attachScreenshotOnlyWhenResumed = false;

/// Screenshots will be cached for 100ms per default. Change this to change
/// the duration, or set to zero if you want to disable screenshot caching.
Duration screenshotCacheDuration = Duration(milliseconds: 100);

/// Sets a callback which is executed before capturing screenshots. Only
/// relevant if `attachScreenshot` is set to true. When false is returned
/// from the function, no screenshot will be attached.
Expand Down
Loading