From d213d2f8fd1b7cc2a37a58c7fc4d058cd02a4f76 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 28 Oct 2024 14:00:30 -0500 Subject: [PATCH] Fix mullti-context active page issue for PlaywrightInstance --- .../Drivers/PlaywrightDriver/PlaywrightInstance.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs index 2bbb0acf..1b0e79ac 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightInstance.cs @@ -9,7 +9,7 @@ public class PlaywrightInstance : IDisposable public IServiceProvider Services => _services; Dictionary _contexts = new Dictionary(); Dictionary> _pages = new Dictionary>(); - IPage? _activePage = null; + Dictionary _activePage = new Dictionary(); /// /// ContextId and BrowserContext @@ -30,14 +30,14 @@ public class PlaywrightInstance : IDisposable { if (string.IsNullOrEmpty(pattern)) { - return _activePage ?? _contexts[contextId].Pages.LastOrDefault(); + return _activePage.ContainsKey(contextId) ? _activePage[contextId] : _contexts[contextId].Pages.LastOrDefault(); } foreach (var page in _contexts[contextId].Pages) { if (page.Url.ToLower() == pattern.ToLower()) { - _activePage = page; + _activePage[contextId] = page; page.BringToFrontAsync().Wait(); return page; } @@ -92,7 +92,7 @@ public class PlaywrightInstance : IDisposable _contexts[ctxId].Page += async (sender, page) => { - _activePage = page; + _activePage[ctxId] = page; _pages[ctxId].Add(page); page.Close += async (sender, e) => { @@ -240,7 +240,7 @@ public class PlaywrightInstance : IDisposable if (page != null) { await page.CloseAsync(); - _activePage = _pages[ctxId].LastOrDefault(); + _activePage[ctxId] = _pages[ctxId].LastOrDefault(); } } }