test webview2
This commit is contained in:
parent
1035170886
commit
e8d182494a
|
|
@ -3,4 +3,6 @@ namespace BotSharp.Abstraction.Browsing.Models;
|
|||
public class BrowserActionArgs
|
||||
{
|
||||
public bool Headless { get; set; }
|
||||
public string? UserDataDir { get; set; }
|
||||
public string? RemoteHostUrl { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Aspects.Cache" Version="2.0.4" />
|
||||
<PackageReference Include="DistributedLock.Redis" Version="1.0.3" />
|
||||
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.7.0" />
|
||||
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.7.1" />
|
||||
<PackageReference Include="Fluid.Core" Version="2.11.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
||||
|
|
|
|||
|
|
@ -45,28 +45,36 @@ public class PlaywrightInstance : IDisposable
|
|||
_playwright = await Playwright.CreateAsync();
|
||||
}
|
||||
|
||||
string tempFolderPath = $"{Path.GetTempPath()}\\playwright\\{ctxId}";
|
||||
|
||||
_contexts[ctxId] = await _playwright.Chromium.LaunchPersistentContextAsync(tempFolderPath, new BrowserTypeLaunchPersistentContextOptions
|
||||
if (!string.IsNullOrEmpty(args.RemoteHostUrl))
|
||||
{
|
||||
Headless = args.Headless,
|
||||
Channel = "chrome",
|
||||
ViewportSize = new ViewportSize
|
||||
var browser = await _playwright.Chromium.ConnectOverCDPAsync(args.RemoteHostUrl);
|
||||
_contexts[ctxId] = browser.Contexts[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
string userDataDir = args.UserDataDir ?? $"{Path.GetTempPath()}\\playwright\\{ctxId}";
|
||||
_contexts[ctxId] = await _playwright.Chromium.LaunchPersistentContextAsync(userDataDir, new BrowserTypeLaunchPersistentContextOptions
|
||||
{
|
||||
Width = 1600,
|
||||
Height = 900
|
||||
},
|
||||
IgnoreDefaultArgs =
|
||||
[
|
||||
"--enable-automation",
|
||||
],
|
||||
Args =
|
||||
[
|
||||
"--disable-infobars",
|
||||
"--test-type"
|
||||
// "--start-maximized"
|
||||
]
|
||||
});
|
||||
Headless = args.Headless,
|
||||
Channel = "chrome",
|
||||
ViewportSize = new ViewportSize
|
||||
{
|
||||
Width = 1600,
|
||||
Height = 900
|
||||
},
|
||||
IgnoreDefaultArgs =
|
||||
[
|
||||
"--enable-automation",
|
||||
],
|
||||
Args =
|
||||
[
|
||||
"--disable-infobars",
|
||||
"--test-type"
|
||||
// "--start-maximized"
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
_pages[ctxId] = new List<IPage>();
|
||||
|
||||
_contexts[ctxId].Page += async (sender, page) =>
|
||||
|
|
|
|||
|
|
@ -8,22 +8,30 @@ public partial class PlaywrightWebDriver
|
|||
var context = await _instance.GetContext(message.ContextId);
|
||||
try
|
||||
{
|
||||
var page = await _instance.NewPage(message, enableResponseCallback: args.EnableResponseCallback,
|
||||
responseInMemory: args.ResponseInMemory,
|
||||
responseContainer: args.ResponseContainer,
|
||||
excludeResponseUrls: args.ExcludeResponseUrls,
|
||||
includeResponseUrls: args.IncludeResponseUrls);
|
||||
|
||||
Serilog.Log.Information($"goto page: {args.Url}");
|
||||
|
||||
if (args.OpenNewTab && page != null && page.Url == "about:blank")
|
||||
IPage? page = null;
|
||||
if (!args.OpenNewTab && !args.EnableResponseCallback)
|
||||
{
|
||||
page = await _instance.NewPage(message,
|
||||
enableResponseCallback: args.EnableResponseCallback,
|
||||
page = _instance.Contexts[message.ContextId].Pages.LastOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
page = await _instance.NewPage(message, enableResponseCallback: args.EnableResponseCallback,
|
||||
responseInMemory: args.ResponseInMemory,
|
||||
responseContainer: args.ResponseContainer,
|
||||
excludeResponseUrls: args.ExcludeResponseUrls,
|
||||
includeResponseUrls: args.IncludeResponseUrls);
|
||||
|
||||
Serilog.Log.Information($"goto page: {args.Url}");
|
||||
|
||||
if (args.OpenNewTab && page != null && page.Url == "about:blank")
|
||||
{
|
||||
page = await _instance.NewPage(message,
|
||||
enableResponseCallback: args.EnableResponseCallback,
|
||||
responseInMemory: args.ResponseInMemory,
|
||||
responseContainer: args.ResponseContainer,
|
||||
excludeResponseUrls: args.ExcludeResponseUrls,
|
||||
includeResponseUrls: args.IncludeResponseUrls);
|
||||
}
|
||||
}
|
||||
|
||||
if (page == null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue