forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaywrightWebDriver.GoToPage.cs
More file actions
65 lines (59 loc) · 2.17 KB
/
PlaywrightWebDriver.GoToPage.cs
File metadata and controls
65 lines (59 loc) · 2.17 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
62
63
64
65
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
public partial class PlaywrightWebDriver
{
public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionArgs args)
{
var result = new BrowserActionResult();
var context = await _instance.GetContext(message.ContextId);
try
{
// Check if the page is already open
/*if (!args.OpenNewTab && context.Pages.Count > 0)
{
foreach (var p in context.Pages)
{
if (p.Url == args.Url)
{
// Disable this due to performance issue, some page is too large
// result.Body = await p.ContentAsync();
result.IsSuccess = true;
// await p.BringToFrontAsync();
return result;
}
}
}*/
var page = args.OpenNewTab ? await _instance.NewPage(message, _services) :
_instance.GetPage(message.ContextId);
Serilog.Log.Information($"goto page: {args.Url}");
var response = await page.GotoAsync(args.Url, new PageGotoOptions
{
Timeout = args.Timeout
});
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
if (args.WaitForNetworkIdle)
{
await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new PageWaitForLoadStateOptions
{
Timeout = args.Timeout
});
}
if (response.Status == 200)
{
// Disable this due to performance issue, some page is too large
// result.Body = await page.InnerHTMLAsync("body");
result.IsSuccess = true;
}
else
{
result.Message = response.StatusText;
}
}
catch (Exception ex)
{
result.Message = ex.Message;
result.StackTrace = ex.StackTrace;
_logger.LogError(ex.Message);
}
return result;
}
}