Reputation: 831
I have used .NetCore2 App and try to takes the screenshot of given URL. It works perfect on local but After deploy to Azure have problems on create Webdriver.
at OpenQA.Selenium.DriverService..ctor(String servicePath, Int32 port, String driverServiceExecutableName, Uri driverServiceDownloadUrl)
↵ at OpenQA.Selenium.Chrome.ChromeDriverService..ctor(String executablePath, String executableFileName, Int32 port)
↵ at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
↵ at SceenshotApp.Service.Screenshot.TakeScreenshot(String url, Int32 width, Int32 height, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Service\Screenshot.cs:line 21
↵ at SceenshotApp.Controllers.HomeController.TakeScreenshot(String url, Int32 width, Int32 height, Int32 scale, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Controllers\HomeController.cs:line 51"
below my code
public static string GetScreenshot(string url)
{
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
driver.Manage().Window.Size = new System.Drawing.Size(1000, 768);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
driver.Navigate().GoToUrl(url);
driver.Close();
driver.Quit();
return path;
}
How can I use Chrome driver on Azure?
Upvotes: 3
Views: 3863
Reputation: 24128
As @IvanYang said, Selenium
is not supported on Azure App Service for Windows, as the figure below from Azure Web App sandbox
.
The reason is Win32k.sys (User32/GDI32) Restrictions
However, you can try to deploy your .net core app to Azure App Service on Linux, which be based on docker image.
So you can follow the quick start tutorial Create an ASP.NET Core app in App Service on Linux
to migrate your current app for Linux. And due to Selenium
requires headless chrome, you must have to install chromium
or chrome
or their headless distributions and webdriver in the docker image or write in the Dockerfile first, please refer to the offical document Tutorial: Build a custom image and run in App Service from a private registry
to know it.
As reference, there are many blogs which helps for you and you can search via Google/Bing, such as Selenium in Docker with DotNetCore Chrome in Linux and Headless Mode
.
Hope it helps.
Upvotes: 6