Skip to content

Commit 8523a6d

Browse files
committed
add event processor for html
1 parent 5598f4c commit 8523a6d

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'dart:html' as html show window, Window;
2+
3+
import '../../../sentry_flutter.dart';
4+
import 'url_filter_event_processor.dart';
5+
// ignore: implementation_imports
6+
import 'package:sentry/src//utils/regex_utils.dart';
7+
8+
// ignore_for_file: invalid_use_of_internal_member
9+
10+
UrlFilterEventProcessor urlFilterEventProcessor(SentryFlutterOptions options) =>
11+
WebUrlFilterEventProcessor(options);
12+
13+
class WebUrlFilterEventProcessor implements UrlFilterEventProcessor {
14+
WebUrlFilterEventProcessor(
15+
this._options,
16+
);
17+
18+
final html.Window _window = html.window;
19+
20+
final SentryFlutterOptions _options;
21+
22+
@override
23+
SentryEvent? apply(SentryEvent event, Hint hint) {
24+
final url = event.request?.url ?? _window.location.toString();
25+
26+
if (_options.allowUrls.isNotEmpty &&
27+
!isMatchingRegexPattern(url, _options.allowUrls)) {
28+
return null;
29+
}
30+
31+
if (_options.denyUrls.isNotEmpty &&
32+
isMatchingRegexPattern(url, _options.denyUrls)) {
33+
return null;
34+
}
35+
36+
return event;
37+
}
38+
}

flutter/lib/src/event_processor/url_filter/url_filter_event_processor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '../../../sentry_flutter.dart';
22
import 'io_url_filter_event_processor.dart'
3-
if (dart.library.html) 'web_url_filter_event_processor.dart';
3+
if (dart.library.html) 'html_url_filter_event_processor.dart'
4+
if (dart.library.js_interop) 'web_url_filter_event_processor.dart';
45

56
abstract class UrlFilterEventProcessor implements EventProcessor {
67
factory UrlFilterEventProcessor(SentryFlutterOptions options) =>

0 commit comments

Comments
 (0)