2024-01-03 19:40:41 +00:00
|
|
|
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
|
2024-01-03 04:43:37 +00:00
|
|
|
|
|
|
|
|
public class PlaywrightInstance : IDisposable
|
|
|
|
|
{
|
|
|
|
|
IPlaywright _playwright;
|
|
|
|
|
IBrowser _browser;
|
|
|
|
|
IPage _page;
|
|
|
|
|
|
2024-01-06 03:24:13 +00:00
|
|
|
// public IPlaywright Playwright => _playwright;
|
2024-01-03 04:43:37 +00:00
|
|
|
public IBrowser Browser => _browser;
|
|
|
|
|
public IPage Page => _page;
|
|
|
|
|
|
2024-01-06 03:24:13 +00:00
|
|
|
public async Task InitInstance()
|
|
|
|
|
{
|
|
|
|
|
if (_playwright == null)
|
|
|
|
|
{
|
|
|
|
|
_playwright = await Playwright.CreateAsync();
|
|
|
|
|
|
2024-01-27 14:58:51 +00:00
|
|
|
/*_browser = await _playwright.Chromium.LaunchPersistentContextAsync(@"C:\Users\haipi\AppData\Local\Google\Chrome\User Data", new BrowserTypeLaunchPersistentContextOptions
|
|
|
|
|
{
|
|
|
|
|
Headless = false,
|
|
|
|
|
Channel = "chrome",
|
|
|
|
|
});*/
|
2024-01-06 03:24:13 +00:00
|
|
|
_browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
|
|
|
|
|
{
|
|
|
|
|
Headless = false,
|
|
|
|
|
Channel = "chrome",
|
2024-01-06 22:24:22 +00:00
|
|
|
Args = new[]
|
|
|
|
|
{
|
|
|
|
|
"--start-maximized"
|
|
|
|
|
}
|
2024-01-06 03:24:13 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 04:43:37 +00:00
|
|
|
public void SetPage(IPage page) { _page = page; }
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_playwright.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|