From 6f37d217db7d8a05d784184375259043e168fedb Mon Sep 17 00:00:00 2001 From: qwsdcvghyu89 <61093706+qwsdcvghyu89@users.noreply.github.com> Date: Sun, 16 Nov 2025 00:37:17 +1100 Subject: [PATCH] Add Addon record and support for utility addons Introduces the Addon record to represent browser addons and updates StealthConfig to support loading multiple utility addons per browser. The Firefox driver now installs specified addons from the UtilityAddons array, improving extensibility for browser automation. --- Beam.Stealth/Addon.cs | 3 +++ Beam.Stealth/StealthConfig.cs | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 Beam.Stealth/Addon.cs diff --git a/Beam.Stealth/Addon.cs b/Beam.Stealth/Addon.cs new file mode 100644 index 0000000..a780a93 --- /dev/null +++ b/Beam.Stealth/Addon.cs @@ -0,0 +1,3 @@ +namespace Beam.Stealth; + +public record Addon(Browser Browser, string AddonPath); \ No newline at end of file diff --git a/Beam.Stealth/StealthConfig.cs b/Beam.Stealth/StealthConfig.cs index e5073b0..a53e119 100644 --- a/Beam.Stealth/StealthConfig.cs +++ b/Beam.Stealth/StealthConfig.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Chromium; using OpenQA.Selenium.Edge; using OpenQA.Selenium.Remote; @@ -23,7 +24,7 @@ namespace Beam.Stealth { public required IWebDriver Driver { get; init; } public string? RemoteAddress { get; init; } - + private StealthConfig(string downloadDir) => DownloadsDirectory = downloadDir; /* ---------- browser-specific option builders ---------- */ @@ -78,6 +79,7 @@ namespace Beam.Stealth { TimeSpan? timeOut = null, Browser preferredBrowser = Browser.Firefox, string? remoteAddress = null, + Addon[]? utilityAddons = null, ILogger? logger = null) { // pick or create a dedicated download folder downloadDir ??= Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); @@ -104,11 +106,12 @@ namespace Beam.Stealth { driver = def.Factory(def.Options); try { - if (driver is FirefoxDriver fd) - fd.InstallAddOnFromFile("uBlock0_1.67.0.firefox.signed.xpi"); + foreach(var addon in utilityAddons) + if (addon.Browser == Browser.Firefox && driver is FirefoxDriver fd) + fd.InstallAddOnFromFile(addon.AddonPath); } catch { - logger?.LogWarning("Unable to load utility extensions"); + logger?.LogWarning("Unable to load utility addons"); } break; @@ -131,6 +134,7 @@ namespace Beam.Stealth { return new StealthConfig(downloadDir) { ShowBrowser = showBrowser, TimeOut = timeOut ?? Timeout.InfiniteTimeSpan, + RemoteAddress = remoteAddress, Logger = logger, Driver = driver };