Skip to content

Commit e8d1824

Browse files
committed
test webview2
1 parent 1035170 commit e8d1824

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/Models/BrowserActionArgs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ namespace BotSharp.Abstraction.Browsing.Models;
33
public class BrowserActionArgs
44
{
55
public bool Headless { get; set; }
6+
public string? UserDataDir { get; set; }
7+
public string? RemoteHostUrl { get; set; }
68
}

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
<ItemGroup>
191191
<PackageReference Include="Aspects.Cache" Version="2.0.4" />
192192
<PackageReference Include="DistributedLock.Redis" Version="1.0.3" />
193-
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.7.0" />
193+
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.7.1" />
194194
<PackageReference Include="Fluid.Core" Version="2.11.1" />
195195
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
196196
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,36 @@ public async Task<IBrowserContext> InitContext(string ctxId, BrowserActionArgs a
4545
_playwright = await Playwright.CreateAsync();
4646
}
4747

48-
string tempFolderPath = $"{Path.GetTempPath()}\\playwright\\{ctxId}";
49-
50-
_contexts[ctxId] = await _playwright.Chromium.LaunchPersistentContextAsync(tempFolderPath, new BrowserTypeLaunchPersistentContextOptions
48+
if (!string.IsNullOrEmpty(args.RemoteHostUrl))
49+
{
50+
var browser = await _playwright.Chromium.ConnectOverCDPAsync(args.RemoteHostUrl);
51+
_contexts[ctxId] = browser.Contexts[0];
52+
}
53+
else
5154
{
52-
Headless = args.Headless,
53-
Channel = "chrome",
54-
ViewportSize = new ViewportSize
55+
string userDataDir = args.UserDataDir ?? $"{Path.GetTempPath()}\\playwright\\{ctxId}";
56+
_contexts[ctxId] = await _playwright.Chromium.LaunchPersistentContextAsync(userDataDir, new BrowserTypeLaunchPersistentContextOptions
5557
{
56-
Width = 1600,
57-
Height = 900
58-
},
59-
IgnoreDefaultArgs =
60-
[
61-
"--enable-automation",
62-
],
63-
Args =
64-
[
65-
"--disable-infobars",
66-
"--test-type"
67-
// "--start-maximized"
68-
]
69-
});
58+
Headless = args.Headless,
59+
Channel = "chrome",
60+
ViewportSize = new ViewportSize
61+
{
62+
Width = 1600,
63+
Height = 900
64+
},
65+
IgnoreDefaultArgs =
66+
[
67+
"--enable-automation",
68+
],
69+
Args =
70+
[
71+
"--disable-infobars",
72+
"--test-type"
73+
// "--start-maximized"
74+
]
75+
});
76+
}
77+
7078
_pages[ctxId] = new List<IPage>();
7179

7280
_contexts[ctxId].Page += async (sender, page) =>

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.GoToPage.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,30 @@ public async Task<BrowserActionResult> GoToPage(MessageInfo message, PageActionA
88
var context = await _instance.GetContext(message.ContextId);
99
try
1010
{
11-
var page = await _instance.NewPage(message, enableResponseCallback: args.EnableResponseCallback,
11+
IPage? page = null;
12+
if (!args.OpenNewTab && !args.EnableResponseCallback)
13+
{
14+
page = _instance.Contexts[message.ContextId].Pages.LastOrDefault();
15+
}
16+
else
17+
{
18+
page = await _instance.NewPage(message, enableResponseCallback: args.EnableResponseCallback,
1219
responseInMemory: args.ResponseInMemory,
1320
responseContainer: args.ResponseContainer,
1421
excludeResponseUrls: args.ExcludeResponseUrls,
1522
includeResponseUrls: args.IncludeResponseUrls);
1623

17-
Serilog.Log.Information($"goto page: {args.Url}");
24+
Serilog.Log.Information($"goto page: {args.Url}");
1825

19-
if (args.OpenNewTab && page != null && page.Url == "about:blank")
20-
{
21-
page = await _instance.NewPage(message,
22-
enableResponseCallback: args.EnableResponseCallback,
23-
responseInMemory: args.ResponseInMemory,
24-
responseContainer: args.ResponseContainer,
25-
excludeResponseUrls: args.ExcludeResponseUrls,
26-
includeResponseUrls: args.IncludeResponseUrls);
26+
if (args.OpenNewTab && page != null && page.Url == "about:blank")
27+
{
28+
page = await _instance.NewPage(message,
29+
enableResponseCallback: args.EnableResponseCallback,
30+
responseInMemory: args.ResponseInMemory,
31+
responseContainer: args.ResponseContainer,
32+
excludeResponseUrls: args.ExcludeResponseUrls,
33+
includeResponseUrls: args.IncludeResponseUrls);
34+
}
2735
}
2836

2937
if (page == null)

0 commit comments

Comments
 (0)