I have created a Blazor server webapp that uses Selenium to scrape a canvas tab on an external website. The webapp works fine when I run it in Visual Studio, but it creates an exception when deployed to Azure. The exception message is:
WebDriverException: Selenium Manager process exited abnormally with 65 code: C:\home\site\wwwroot\selenium-manager\windows\selenium-manager.exe --browser "chrome" --language-binding csharp --output json Standard Output >> { "logs": [ { "level": "ERROR", "timestamp": 1739662865, "message": "There is not enough space on the disk. (os error 112)" } ], "result": { "code": 65, "message": "There is not enough space on the disk. (os error 112)", "driver_path": "", "browser_path": "" } }
The relevant Blazor code is:
using HtmlAgilityPack;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
public class CanvasScraperService
{
private static string YahooAnalysisURL(string ticker)
{
var tickerUpper = ticker.ToUpper();
return $"/{tickerUpper}/analysis/";
}
public string ScrapeCanvasImage(string ticker)
{
// Set up Chrome options for headless mode
var options = new ChromeOptions();
options.AddArgument("--headless"); // Runs in headless mode (no GUI)
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
using IWebDriver driver = new ChromeDriver(options);
//Set the maximum wait time for the page to load
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
try
{
driver.Navigate().GoToUrl(YahooAnalysisURL(ticker));
//Wait for the page to load completely
System.Threading.Thread.Sleep(1000);
}
//The page might not fully load within the specified time. Ignore the exception if it occurs.
catch (WebDriverTimeoutException)
{
}
// Execute JavaScript to get the canvas data URL. The canvas element is the third canvas element on the page.
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string script = @"var canvasList = document.querySelectorAll('canvas');
return canvasList[2].toDataURL('image/png');
";
string dataUrl = (string)js.ExecuteScript(script);
driver.Quit();
return dataUrl;
}
}`