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:
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Beam.Stealth;
|
||||||
|
|
||||||
|
public record Addon(Browser Browser, string AddonPath);
|
||||||
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using OpenQA.Selenium;
|
using OpenQA.Selenium;
|
||||||
using OpenQA.Selenium.Firefox;
|
using OpenQA.Selenium.Firefox;
|
||||||
using OpenQA.Selenium.Chrome;
|
using OpenQA.Selenium.Chrome;
|
||||||
|
using OpenQA.Selenium.Chromium;
|
||||||
using OpenQA.Selenium.Edge;
|
using OpenQA.Selenium.Edge;
|
||||||
using OpenQA.Selenium.Remote;
|
using OpenQA.Selenium.Remote;
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ namespace Beam.Stealth {
|
|||||||
public required IWebDriver Driver { get; init; }
|
public required IWebDriver Driver { get; init; }
|
||||||
|
|
||||||
public string? RemoteAddress { get; init; }
|
public string? RemoteAddress { get; init; }
|
||||||
|
|
||||||
private StealthConfig(string downloadDir) => DownloadsDirectory = downloadDir;
|
private StealthConfig(string downloadDir) => DownloadsDirectory = downloadDir;
|
||||||
|
|
||||||
/* ---------- browser-specific option builders ---------- */
|
/* ---------- browser-specific option builders ---------- */
|
||||||
@@ -78,6 +79,7 @@ namespace Beam.Stealth {
|
|||||||
TimeSpan? timeOut = null,
|
TimeSpan? timeOut = null,
|
||||||
Browser preferredBrowser = Browser.Firefox,
|
Browser preferredBrowser = Browser.Firefox,
|
||||||
string? remoteAddress = null,
|
string? remoteAddress = null,
|
||||||
|
Addon[]? utilityAddons = null,
|
||||||
ILogger? logger = null) {
|
ILogger? logger = null) {
|
||||||
// pick or create a dedicated download folder
|
// pick or create a dedicated download folder
|
||||||
downloadDir ??= Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
downloadDir ??= Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||||
@@ -104,11 +106,12 @@ namespace Beam.Stealth {
|
|||||||
driver = def.Factory(def.Options);
|
driver = def.Factory(def.Options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (driver is FirefoxDriver fd)
|
foreach(var addon in utilityAddons)
|
||||||
fd.InstallAddOnFromFile("uBlock0_1.67.0.firefox.signed.xpi");
|
if (addon.Browser == Browser.Firefox && driver is FirefoxDriver fd)
|
||||||
|
fd.InstallAddOnFromFile(addon.AddonPath);
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
logger?.LogWarning("Unable to load utility extensions");
|
logger?.LogWarning("Unable to load utility addons");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -131,6 +134,7 @@ namespace Beam.Stealth {
|
|||||||
return new StealthConfig(downloadDir) {
|
return new StealthConfig(downloadDir) {
|
||||||
ShowBrowser = showBrowser,
|
ShowBrowser = showBrowser,
|
||||||
TimeOut = timeOut ?? Timeout.InfiniteTimeSpan,
|
TimeOut = timeOut ?? Timeout.InfiniteTimeSpan,
|
||||||
|
RemoteAddress = remoteAddress,
|
||||||
Logger = logger,
|
Logger = logger,
|
||||||
Driver = driver
|
Driver = driver
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user