diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs index 1f5f9d51..252f5f9a 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs @@ -70,8 +70,9 @@ public class PlaywrightInstance : IDisposable { if (_contexts.ContainsKey(id)) { - await _contexts[id].Pages.Last().WaitForLoadStateAsync(LoadState.DOMContentLoaded); - await _contexts[id].Pages.Last().WaitForLoadStateAsync(LoadState.NetworkIdle); + var page = _contexts[id].Pages.Last(); + await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded); + await page.WaitForLoadStateAsync(LoadState.NetworkIdle); } await Task.Delay(100); } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.Screenshot.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.Screenshot.cs index b3a58d50..bab41e4c 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.Screenshot.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.Screenshot.cs @@ -5,12 +5,14 @@ public partial class PlaywrightWebDriver { public async Task ScreenshotAsync(string conversationId, string path) { - var bytes = await _instance.GetPage(conversationId) - .ScreenshotAsync(new PageScreenshotOptions - { - Path = path, - Animations = ScreenshotAnimations.Disabled - }); + await _instance.Wait(conversationId); + var page = _instance.GetPage(conversationId); + + await Task.Delay(500); + var bytes = await page.ScreenshotAsync(new PageScreenshotOptions + { + Path = path + }); return "data:image/png;base64," + Convert.ToBase64String(bytes); } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScreenshotFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScreenshotFn.cs index f773799e..1d133ad1 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScreenshotFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScreenshotFn.cs @@ -22,7 +22,7 @@ public class ScreenshotFn : IFunctionCallback var path = webDriverService.GetScreenshotFilePath(message.MessageId); message.Data = await _browser.ScreenshotAsync(convService.ConversationId, path); - message.Content = "Took screenshot completed"; + message.Content = "Took screenshot completed. You can take another screenshot if needed."; return true; } diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScrollPageFn.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScrollPageFn.cs index 09121877..3d491454 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScrollPageFn.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Functions/ScrollPageFn.cs @@ -23,7 +23,7 @@ public class ScrollPageFn : IFunctionCallback var agent = await agentService.LoadAgent(message.CurrentAgentId); message.Data = await _browser.ScrollPageAsync(new BrowserActionParams(agent, args, convService.ConversationId, message.MessageId)); - message.Content = "Scrolled"; + message.Content = "Scrolled. You can scroll more if needed."; var webDriverService = _services.GetRequiredService(); var path = webDriverService.GetScreenshotFilePath(message.MessageId);