Merge pull request #929 from visagang/features/vguruparan

Update headless setting for Playwright
This commit is contained in:
Haiping 2025-03-11 09:11:05 -05:00 committed by GitHub
commit 72a49a0a1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View file

@ -3,4 +3,5 @@ namespace BotSharp.Abstraction.Browsing.Settings;
public class WebBrowsingSettings
{
public string Driver { get; set; } = "Playwright";
public bool Headless { get; set; }
}

View file

@ -1,4 +1,5 @@
using Azure;
using BotSharp.Abstraction.Browsing.Settings;
using System.IO;
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
@ -33,9 +34,10 @@ public class PlaywrightInstance : IDisposable
public async Task<IBrowserContext> GetContext(string ctxId)
{
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
if (!_contexts.ContainsKey(ctxId))
{
await InitContext(ctxId, new BrowserActionArgs());
await InitContext(ctxId, new BrowserActionArgs() { Headless = _webDriver.Headless });
}
return _contexts[ctxId];
}

View file

@ -1,3 +1,5 @@
using BotSharp.Abstraction.Browsing.Settings;
namespace BotSharp.Plugin.WebDriver.Functions;
public class OpenBrowserFn : IFunctionCallback
@ -6,12 +8,15 @@ public class OpenBrowserFn : IFunctionCallback
private readonly IServiceProvider _services;
private readonly IWebBrowser _browser;
private readonly WebBrowsingSettings _webBrowsingSettings;
public OpenBrowserFn(IServiceProvider services,
IWebBrowser browser)
IWebBrowser browser,
WebBrowsingSettings webBrowsingSettings)
{
_services = services;
_browser = browser;
_webBrowsingSettings = webBrowsingSettings;
}
public async Task<bool> Execute(RoleDialogModel message)
@ -31,7 +36,7 @@ public class OpenBrowserFn : IFunctionCallback
};
var result = await _browser.LaunchBrowser(msgInfo, new BrowserActionArgs
{
Headless = false
Headless = _webBrowsingSettings.Headless
});
result = await _browser.GoToPage(msgInfo, new PageActionArgs
{