Skip to content

Commit

Permalink
Add basic network monitoring (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
aluhrs13 authored Jan 16, 2024
1 parent 52855f2 commit c7c43e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions SampleApps/WV2CDPExtensionWPFSample/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<MenuItem Header="Subscribe" Click="SubscribeToDownloadWillBegin"/>
<MenuItem Header="Unsubscribe" Click="UnsubscribeFromDownloadWillBegin"/>
</MenuItem>
<MenuItem Header="RequestReponseLogs">
<MenuItem Header="Subscribe" Click="SubscribeToNetworkBasics"/>
<MenuItem Header="Unsubscribe" Click="UnsubscribeFromNetworkBasics"/>
</MenuItem>
</MenuItem>
</Menu>
<DockPanel DockPanel.Dock="Top">
Expand Down
25 changes: 25 additions & 0 deletions SampleApps/WV2CDPExtensionWPFSample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Web.WebView2.Core.DevToolsProtocolExtension;
using System.Text;
using System.Linq;
using System.Text.Json;

namespace WV2CDPExtensionSample
{
Expand Down Expand Up @@ -194,6 +195,30 @@ void PrintDownloadWillBegin(object sender, Page.DownloadWillBeginEventArgs args)
{
Trace.WriteLine(String.Format("DownloadWillBegin Event Args - FrameId: {0} Guid: {1} URL: {2}", args.FrameId, args.Guid, args.Url));
}

async void SubscribeToNetworkBasics(object sender, RoutedEventArgs e)
{
await cdpHelper.Network.EnableAsync();
cdpHelper.Network.ResponseReceived += PrintResponseInfo;
cdpHelper.Network.RequestWillBeSent += PrintRequestInfo;
}

void PrintResponseInfo(object sender, Network.ResponseReceivedEventArgs args)
{
Trace.WriteLine(JsonSerializer.Serialize<Network.ResponseReceivedEventArgs>(args));
}

void PrintRequestInfo(object sender, Network.RequestWillBeSentEventArgs args)
{
Trace.WriteLine(JsonSerializer.Serialize<Network.RequestWillBeSentEventArgs>(args));
}

async void UnsubscribeFromNetworkBasics(object sender, RoutedEventArgs e)
{
cdpHelper.Network.ResponseReceived -= PrintResponseInfo;
cdpHelper.Network.RequestWillBeSent -= PrintRequestInfo;
await cdpHelper.Network.DisableAsync();
}
#endregion
}
}

0 comments on commit c7c43e5

Please sign in to comment.