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.
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user