2
votes

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?

1
Due to azure web app sandbox, the selenium is not supported on azure web app.Ivan Yang
@Ivan Yang : thanks for reply, any alternatives ?Nayeem Mansoori
It's not a good solution, but it can work if deploys to azure vm.Ivan Yang
my path is under Nuget package Selenium.Chrome.WebDriverNayeem Mansoori
@Dimitar : I'm using var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);Nayeem Mansoori

1 Answers

3
votes

As @IvanYang said, Selenium is not supported on Azure App Service for Windows, as the figure below from Azure Web App sandbox.

enter image description here

The reason is Win32k.sys (User32/GDI32) Restrictions

enter image description here

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.