Skip to content

Commit b8083b2

Browse files
author
Visagan Guruparan
committed
Fetch WebDrive headless setting from config
1 parent 7571512 commit b8083b2

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/Settings/WebBrowsingSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ namespace BotSharp.Abstraction.Browsing.Settings;
33
public class WebBrowsingSettings
44
{
55
public string Driver { get; set; } = "Playwright";
6+
public bool Headless { get; set; }
67
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Azure;
2+
using BotSharp.Abstraction.Browsing.Settings;
23
using System.IO;
34

45
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
@@ -33,13 +34,10 @@ public void SetServiceProvider(IServiceProvider services)
3334

3435
public async Task<IBrowserContext> GetContext(string ctxId)
3536
{
36-
var headless = true;
37-
#if DEBUG
38-
headless = false;
39-
#endif
37+
var _webDriver = _services.GetRequiredService<WebBrowsingSettings>();
4038
if (!_contexts.ContainsKey(ctxId))
4139
{
42-
await InitContext(ctxId, new BrowserActionArgs() { Headless = headless });
40+
await InitContext(ctxId, new BrowserActionArgs() { Headless = _webDriver.Headless });
4341
}
4442
return _contexts[ctxId];
4543
}

src/Plugins/BotSharp.Plugin.WebDriver/Functions/OpenBrowserFn.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using BotSharp.Abstraction.Browsing.Settings;
2+
13
namespace BotSharp.Plugin.WebDriver.Functions;
24

35
public class OpenBrowserFn : IFunctionCallback
@@ -6,12 +8,15 @@ public class OpenBrowserFn : IFunctionCallback
68

79
private readonly IServiceProvider _services;
810
private readonly IWebBrowser _browser;
11+
private readonly WebBrowsingSettings _webBrowsingSettings;
912

1013
public OpenBrowserFn(IServiceProvider services,
11-
IWebBrowser browser)
14+
IWebBrowser browser,
15+
WebBrowsingSettings webBrowsingSettings)
1216
{
1317
_services = services;
1418
_browser = browser;
19+
_webBrowsingSettings = webBrowsingSettings;
1520
}
1621

1722
public async Task<bool> Execute(RoleDialogModel message)
@@ -29,13 +34,9 @@ public async Task<bool> Execute(RoleDialogModel message)
2934
ContextId = convService.ConversationId,
3035
MessageId = message.MessageId
3136
};
32-
var headless = true;
33-
#if DEBUG
34-
headless = false;
35-
#endif
3637
var result = await _browser.LaunchBrowser(msgInfo, new BrowserActionArgs
3738
{
38-
Headless = headless
39+
Headless = _webBrowsingSettings.Headless
3940
});
4041
result = await _browser.GoToPage(msgInfo, new PageActionArgs
4142
{

0 commit comments

Comments
 (0)