iOS session replay records a Mapbox `UiKitView` as a black box, even with `maskAllPlatformViews = false`

Đang mở
#593 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart, flutter, ios, swift
Lĩnh vực
mobile, observability

Hướng nghiên cứu

Bắt đầu với screenshot_capturer.dart ở dòng 419 và 610, sau đó kiểm tra darwin/.../PosthogFlutterPlugin.swift quanh captureOneNative tại dòng 744. Tái hiện trường hợp Mapbox UiKitView và lần theo đường đi captured-to-nil-to-mask. Hoàn tất khi một iOS platform view không bị che xuất hiện trong bản replay, trong khi các platform views bị che vẫn được bảo vệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement feature/replay
Version

5.44.2

Steps to Reproduce

Environment: posthog_flutter 5.44.2, mapbox_maps_flutter 2.24.3, Flutter stable, iOS 27.0 simulator (iPhone 18 Pro).

  1. Add a mapbox_maps_flutter MapWidget to a screen. On iOS that plugin renders a plain UiKitView — the only iOS branch, with no texture-mode option (lib/src/mapbox_maps_platform.dart:80):
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
  return UiKitView(
    viewType: 'plugins.flutter.io/mapbox_maps',
    ...
  1. Enable session replay with every mask off:
await Posthog().setup(
  PostHogConfig('<token>')
    ..sessionReplay = true
    ..sessionReplayConfig = (PostHogSessionReplayConfig()
      ..maskAllTexts = false
      ..maskAllImages = false
      ..maskAllPlatformViews = false
      ..captureNativeScreens = true),
);
  1. Wrap the app in PostHogWidget, run on an iOS simulator, and open the screen with the map.
  2. Watch the resulting replay.

Wrapping the map in PostHogPlatformView(privacy: PostHogPlatformViewPrivacy.capture) makes no difference.

Related

Related to #151, which tracked platform view recording and was closed in July 2026 after PR #453 and #473. On iOS the reveal path only covers WKWebView, so the Mapbox case from that thread still reproduces — a maintainer had linked the "Flutter iOS Google Maps does not visible in session replay" question there as the same problem.

Questions

  1. Is non-WebView platform view capture planned for iOS, or is WebView-only the intended scope? If the latter, maskAllPlatformViews should document it.
  2. Could drawHierarchy(in:afterScreenUpdates:) be gated on no masked platform view intersecting the crop rect, keeping the leak protection for mixed screens while letting the fully-unmasked case work?
Expected Result

The map appears in the replay, since platform view masking is disabled globally and maskAllPlatformViews is documented as a global opt-out with no iOS caveat.

Actual Result

The map is a solid black rectangle exactly its own size, while the debug log claims the opposite:

Image
flutter: Found 0 masked and 1 captured platform view rect(s)

That mismatch is what makes this hard to diagnose from the app side: the SDK reports the view as captured, and the replay shows it masked.

Cause. Dart classifies the UiKitView as captured and asks native to screenshot the rect (screenshot_capturer.dart:610). captureOneNative searches that rect for a WKWebView, finds none, and returns nil (darwin/.../PosthogFlutterPlugin.swift:744):

// No WKWebView found for the captured rect. Returning nil here
// keeps this safe: drawHierarchy over the full window would
// include any masked CALayer-backed platform view overlapping
// the crop region and leak it into replay.
onResult(nil)

Dart reads nil as "capture failed" and paints the mask anyway (screenshot_capturer.dart:419):

if (bytes == null) {
  _imageMaskPainter.drawMaskedImage(canvas, [fallbackMask], pixelRatio);
  return;
}

So the view round-trips captured → declined → re-masked, with the log line emitted before the decline.

I have only tested Mapbox, so I can't speak to other plugins, but the WebView-only check is not Mapbox-specific. I have not tested Android either, though its captureOneNative composites platform-view SurfaceViews rather than restricting to web views (android/.../PosthogFlutterPlugin.kt:1216-1221), so the platforms appear to differ.

Ngôn ngữ chính
Dart
Star
99
Fork
94
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
65

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PostHog/posthog-flutter

Tất cả issue của PostHog/posthog-flutter

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.