forked from MasterDevs/ChromeDevTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (46 loc) · 2.22 KB
/
Program.cs
File metadata and controls
50 lines (46 loc) · 2.22 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
using MasterDevs.ChromeDevTools.Protocol.Chrome.Page;
using System;
using System.Linq;
namespace MasterDevs.ChromeDevTools.Sample
{
internal class Program
{
private static void Main(string[] args)
{
// STEP 1 - Run Chrome
var chromeProcessFactory = new ChromeProcessFactory();
using (var chromeProcess = chromeProcessFactory.Create(9222))
{
// STEP 2 - Create a debugging session
var endpointUrl = chromeProcess.GetSessions().Result.LastOrDefault();
var chromeSessionFactory = new ChromeSessionFactory();
var chromeSession = chromeSessionFactory.Create(endpointUrl);
// STEP 3 - Send a command
//
// Here we are sending a command to tell chrome to navigate to
// the specified URL
var navigateResponse = chromeSession.SendAsync(new NavigateCommand
{
Url = "http://www.google.com"
})
.Result;
Console.WriteLine("NavigateResponse: " + navigateResponse.Id);
// STEP 4 - Register for events (in this case, "Page" domain events)
// send an event to tell chrome to send us all Page events
// but we only subscribe to certain events in this session
var pageEnableResult = chromeSession.SendAsync<ChromeDevTools.Protocol.Chrome.Page.EnableCommand>().Result;
Console.WriteLine("PageEnable: " + pageEnableResult.Id);
chromeSession.Subscribe<Protocol.Chrome.Page.DomContentEventFiredEvent>(domContentEvent =>
{
Console.WriteLine("DomContentEvent: " + domContentEvent.Timestamp);
});
// you might never see this, but that's what an event is ... right?
chromeSession.Subscribe<Protocol.Chrome.Page.FrameStartedLoadingEvent>(frameStartedLoadingEvent =>
{
Console.WriteLine("FrameStartedLoading: " + frameStartedLoadingEvent.FrameId);
});
Console.ReadLine();
}
}
}
}