为什么硒chromedriver比常规chrome使用更少的资源 [英] Why does selenium chromedriver use less resources than regular chrome

查看:100
本文介绍了为什么硒chromedriver比常规chrome使用更少的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当通过selenium chromedriver启动带有新用户数据目录的chrome时,它消耗的资源(cpu,内存和磁盘)比正常启动时要少得多.

I have noticed that when launching chrome with fresh user data directories via selenium chromedriver it is using up much less resources (cpu, memory, and disk) than when launching normally.

我能够找到原因之一是硒chromedriver启动时带有以下参数:

One of the reasons I was able to find out was that selenium chromedriver launches with these arguments:

--disable-background-networking
--disable-client-side-phishing-detection
--disable-default-apps
--disable-hang-monitor
--disable-popup-blocking
--disable-prompt-on-repost
--disable-sync
--disable-web-resources
--enable-automation
--enable-logging
--force-fieldtrials=SiteIsolationExtensions/Control
--ignore-certificate-errors
--log-level=0
--metrics-recording-only
--no-first-run
--password-store=basic
--test-type=webdriver 
--use-mock-keychain

应用这些参数后,CPU,内存和磁盘使用率大大下降.但是,磁盘使用率仍然大约高出10倍.使用Windows Resource Monitor,我分析了I/O的使用情况,并看到大量写入chrome_url_fetcher目录和另一个目录的情况,该目录带有两个随机的5位数字,并用下划线分隔;RANDOMNUMBER_RANDOMNUMBER.这两个目录都位于%temp%文件夹中,并且包含名称中包含"pepperflashplayer"的文件.

After applying those arguments, cpu, memory, and disk usage have massively gone down. However, disk usage is still about 10x higher. Using Windows Resource Monitor, I analyzed the I/O usage and saw a lot of writing to chrome_url_fetcher directory and another directory with two random 5 digit numbers seperated by a underscore; RANDOMNUMBER_RANDOMNUMBER. Both of these directories were in the %temp% folder and contained files that included "pepperflashplayer" in their names.

我假设这是铬,它安装了Pepperflash的必要组件,但是为什么硒chromedriver不是这种情况?有什么办法可以阻止我?

I am assuming that this is chrome installing a necessary component for pepperflash, but why is this not the case with selenium chromedriver? Is there any way I can stop this?

推荐答案

ChromeDriver 启动了 v87.0.4280.88 浏览上下文是通过这些附加的

The Selenium driven ChromeDriver initiated google-chrome v87.0.4280.88 browsing context is initiated with these additional Command Line Switches:

  • -disable-background-networking :禁用几个在后台运行网络请求的子系统.
  • -禁用客户端网络钓鱼检测:禁用客户端网络钓鱼检测功能.
  • -disable-default-apps :在首次运行时禁用默认应用程序的安装.在自动测试期间使用.
  • -disable-hang-monitor :禁止渲染器进程中的挂起"监视对话框.
  • -disable-popup-blocking :禁用弹出窗口阻止.
  • -disable-prompt-on-repost :此开关可用于禁用对用户尝试导航到帖子发布结果页面的检查.
  • -disable-sync :禁用将浏览器数据同步到Google帐户.
  • -enable-automation :启用指示浏览器由自动化控制的功能.
  • -enable-blink-features = ShadowDOMV0 :启用一个或多个Blink运行时启用的功能.
  • -enable-logging :控制是否启用控制台日志记录,并有选择地配置其路由位置.
  • -log-level = 0 :设置最低日志级别.
  • -no-first-run :跳过初次运行"任务,无论它实际上是否是初次运行".
  • -no-service-autorun :禁止服务进程将自身添加为自动运行进程.
  • -password-store = basic :指定要使用的加密存储后端.
  • -remote-debugging-port = 0 :在指定端口上通过HTTP启用远程调试.
  • -test-type = webdriver :当前测试工具的类型(浏览器"或"ui"或"webdriver").
  • -use-mock-keychain
  • -user-data-dir =" C:\ Users \ username \ AppData \ Local \ Temp \ scoped_dir9640_113432031 :浏览器存储用户配置文件的目录.
  • data:,
  • --disable-background-networking: Disables several subsystems which run network requests in the background.
  • --disable-client-side-phishing-detection: Disables the client-side phishing detection feature.
  • --disable-default-apps: Disables installation of default apps on first run. This is used during automated testing.
  • --disable-hang-monitor: Suppresses hang monitor dialogs in renderer processes.
  • --disable-popup-blocking: Disables pop-up blocking.
  • --disable-prompt-on-repost: This switch may be used to disable that check that the user had attempted to navigate to a page that was the result of a post.
  • --disable-sync: Disables syncing browser data to a Google Account.
  • --enable-automation: Enables indication that browser is controlled by automation.
  • --enable-blink-features=ShadowDOMV0: Enables one or more Blink runtime-enabled features.
  • --enable-logging: Controls whether console logging is enabled and optionally configures where it's routed.
  • --log-level=0: Sets the minimum log level.
  • --no-first-run: Skip First Run tasks, whether or not it's actually the First Run.
  • --no-service-autorun: Disables the service process from adding itself as an autorun process.
  • --password-store=basic: Specifies which encryption storage backend to use.
  • --remote-debugging-port=0: Enables remote debug over HTTP on the specified port.
  • --test-type=webdriver: Type of the current test harness ("browser" or "ui" or "webdriver").
  • --use-mock-keychain
  • --user-data-dir="C:\Users\username\AppData\Local\Temp\scoped_dir9640_113432031: Directory where the browser stores the user profile.
  • data:,

使用这些额外的命令行开关使 Google Chrome 进程的初始化所需的回调次数更少,并且禁用了更多的

The usage of these additional commandline switches makes the initialization of the Google Chrome process requires less callbacks as well as disables a lot more callbacks

除此之外,常规chrome会话使用的 Flash 是:

Apart from that, Flash used by the regular chrome session is:

32.0.0.465 C:\Users\username\AppData\Local\Google\Chrome\User Data\PepperFlash\32.0.0.465\pepflashplayer.dll

ChromeDriver 启动的Chrome会话使用的 Flash 如下:

Where as, Flash used by the ChromeDriver initiated chrome session is:

30.0.0.154 C:\WINDOWS\system32\Macromed\Flash\pepflashplayer64_30_0_0_154.dll

由于上述原因, ChromeDriver Google Chrome 相比,a>初始化的 Google Chrome 更加轻巧,占用的内存更少.

For the above mentioned reasons the ChromeDriver initiated Google Chrome is lighter and less memory consuming then the regular Google Chrome.

这篇关于为什么硒chromedriver比常规chrome使用更少的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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