Chrome驱动程序无法在Azure Web应用程序上运行 [英] Chrome driver is not working on azure web apps

查看:111
本文介绍了Chrome驱动程序无法在Azure Web应用程序上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用.NetCore2 App并尝试获取给定URL的屏幕截图。它可以在本地完美运行,但是在部署到Azure之后,在创建Webdriver时会遇到问题。

 在OpenQA.Selenium.DriverService..ctor(字符串servicePath,Int32端口,字符串driverServiceExecutableName,Uri driverServiceDownloadUrl)
(位于OpenQA.Selenium.Chrome.ChromeDriverService..ctor(字符串可执行路径,字符串可执行文件名称,Int32端口)
(位于OpenQA.Selenium.Chrome) ChromeDriver..ctor(String chromeDriverDirectory,ChromeOptions选项)
在SceenshotApp.Service.Screenshot.TakeScreenshot(String url,Int32 width,Int32 height,Int32 delay)在D:\Projects\TFT\Bitbucket- Linkury\网站\工具\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\服务\Screenshot.cs:第21行
↵在SceenshotApp.Controllers.HomeController.TakeScreenshot(字符串url,Int32宽度, D:\项目\TFT\Bitbucket-Linkury\网站\工具\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\控制器\HomeCon troller.cs:第51行

在我的代码下方

 公共静态字符串GetScreenshot(字符串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();
返回路径;
}

如何在Azure上使用Chrome驱动程序?

解决方案

正如@IvanYang所说,Azure App不支持 Selenium Windows服务,如下图所示,来自



原因是



但是,您可以尝试将.net核心应用程序部署到基于docker的Linux上的Azure应用服务图像。



因此,您可以按照快速入门教程 在Linux上的App Service中创建ASP.NET Core应用 ,以迁移当前的Linux应用。并且由于需要无头铬,因此必须安装 chrome 或它们在docker映像中的无头发行版和webdriver或先在Dockerfile中编写,请参考正式文档 教程:构建自定义图像并从私有注册表在App Service中运行

作为参考,有很多博客对您有帮助,您可以通过Google / Bing搜索,例如 带有DotNetCore的Docker中的硒Linux和无头模式下的Chrome



希望它会有所帮助。


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?

解决方案

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.

这篇关于Chrome驱动程序无法在Azure Web应用程序上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆