-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebViewPage.cs
More file actions
61 lines (52 loc) · 2.03 KB
/
Copy pathWebViewPage.cs
File metadata and controls
61 lines (52 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Com.Datadog.Android.Webview;
namespace DatadogNet.Android.Example;
/// <summary>
/// A page hosting an <c>Android.Webkit.WebView</c> with the Datadog bridge installed, through the
/// raw <c>DatadogNet.WebView.Android</c> binding.
/// </summary>
/// <remarks>
/// For anything to actually cross the bridge, the page inside must run the Datadog Browser SDK
/// and its host must be on the allowlist — example.com does not, so what this page demonstrates
/// is the wiring. The allowlist matters: the bridge lets page JavaScript write into your RUM
/// session, so it is opt-in per host, matched by suffix.
/// </remarks>
public sealed class WebViewPage : ContentPage
{
private readonly WebView webView;
public WebViewPage()
{
Title = "Web view";
webView = new WebView { Source = "https://example.com/" };
// The platform view exists once the handler has connected, which Loaded guarantees.
// There is no disable on Android - the bridge lives as long as the web view does.
webView.Loaded += OnWebViewLoaded;
var layout = new Grid
{
RowDefinitions =
[
new RowDefinition(GridLength.Auto),
new RowDefinition(GridLength.Star),
],
};
layout.Add(
new Label
{
Padding = 12,
FontSize = 13,
Text = "WebViewTracking is enabled on this WebView. A page running the Datadog "
+ "Browser SDK on an allowlisted host would report into the surrounding "
+ "native session; example.com does not, so the point here is the wiring.",
},
0,
0);
layout.Add(webView, 0, 1);
Content = layout;
}
private void OnWebViewLoaded(object? sender, EventArgs e)
{
if (webView.Handler?.PlatformView is global::Android.Webkit.WebView platform)
{
WebViewTracking.Enable(platform, new List<string> { "example.com" });
}
}
}