feat: add deferred response buffering, TableDataProvider, and stealth improvements
- ApiResponse: add readToBuffer option to defer/stream body instead of eagerly buffering - TableDataProvider: implement HTML table parser with per-column provider support - StealthConfig: add 10s page load timeout and copyCookiesFrom parameter for cookie sharing - StealthUnitDownloader: catch WebDriverTimeoutException on navigation, log warning instead of throwing - Bump version to 2.9.0
This commit is contained in:
@@ -41,6 +41,8 @@ namespace Beam.Stealth {
|
||||
o.SetPreference("pdfjs.disabled", true); // open PDFs externally
|
||||
o.SetPreference("browser.download.manager.showWhenStarting", false);
|
||||
|
||||
o.PageLoadTimeout = TimeSpan.FromSeconds(10);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -56,6 +58,8 @@ namespace Beam.Stealth {
|
||||
// common stability flags
|
||||
o.AddArgument("--no-sandbox");
|
||||
o.AddArgument("--disable-dev-shm-usage");
|
||||
|
||||
o.PageLoadTimeout = TimeSpan.FromSeconds(10);
|
||||
|
||||
return o;
|
||||
}
|
||||
@@ -68,6 +72,8 @@ namespace Beam.Stealth {
|
||||
o.AddUserProfilePreference("download.prompt_for_download", false);
|
||||
o.AddUserProfilePreference("safebrowsing.enabled", false);
|
||||
|
||||
o.PageLoadTimeout = TimeSpan.FromSeconds(10);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -80,7 +86,8 @@ namespace Beam.Stealth {
|
||||
Browser preferredBrowser = Browser.Firefox,
|
||||
string? remoteAddress = null,
|
||||
Addon[]? utilityAddons = null,
|
||||
ILogger? logger = null) {
|
||||
ILogger? logger = null,
|
||||
IWebDriver? copyCookiesFrom = null) {
|
||||
// pick or create a dedicated download folder
|
||||
downloadDir ??= Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(downloadDir);
|
||||
@@ -130,6 +137,11 @@ namespace Beam.Stealth {
|
||||
|
||||
if (driver is null)
|
||||
throw new AggregateException(errors);
|
||||
|
||||
if (copyCookiesFrom != null) {
|
||||
foreach (var cookie in copyCookiesFrom.Manage().Cookies.AllCookies)
|
||||
driver.Manage().Cookies.AddCookie(new Cookie(cookie.Name, cookie.Value, cookie.Domain, cookie.Path, cookie.Expiry));
|
||||
}
|
||||
|
||||
return new StealthConfig(downloadDir) {
|
||||
ShowBrowser = showBrowser,
|
||||
@@ -139,7 +151,7 @@ namespace Beam.Stealth {
|
||||
Driver = driver
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void Dispose() {
|
||||
Driver.Dispose();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ using Beam.Abstractions;
|
||||
using Beam.Downloaders;
|
||||
using Beam.Models;
|
||||
using Beam.Stealth.Strategies;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Firefox;
|
||||
|
||||
namespace Beam.Stealth {
|
||||
using File = System.IO.File;
|
||||
@@ -35,9 +37,15 @@ namespace Beam.Stealth {
|
||||
protected override async Task DownloadToStream(string url, int bufferSize, Stream destinationStream,
|
||||
IProgress<IDownloadReport> progress, CancellationToken ct) {
|
||||
var driver = Config.Driver;
|
||||
await driver.Navigate().GoToUrlAsync(url);
|
||||
await Manipulator(driver);
|
||||
try {
|
||||
await driver.Navigate().GoToUrlAsync(url);
|
||||
}
|
||||
catch (WebDriverTimeoutException) {
|
||||
Logger?.LogWarning("Timeout navigating to {url}", url);
|
||||
}
|
||||
|
||||
await Manipulator(driver);
|
||||
|
||||
await _downloadStrategy.DownloadToStream(url, bufferSize, destinationStream, progress, Config, Logger, ct);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user