首页 > 解决方案 > Why does selenium chromedriver use less resources than regular chrome

问题描述

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.

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

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.

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?

标签: performanceseleniumgoogle-chromeselenium-chromedriver

解决方案


Selenium驱动的ChromeDriver启动 v87.0.4280.88浏览上下文是使用这些额外的命令行开关启动的:

  • --disable-background-networking:禁用几个在后台运行网络请求的子系统。
  • --disable-client-side-phishing-detection:禁用客户端网络钓鱼检测功能。
  • --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:当前测试工具的类型(“browser”或“ui”或“webdriver”)。
  • --use-mock-keychain
  • --user-data-dir="C:\Users\username\AppData\Local\Temp\scoped_dir9640_113432031:浏览器存储用户配置文件的目录。
  • data:,

这些额外的命令行开关的使用使得谷歌浏览器进程的初始化需要更少的回调以及禁用更多的回调

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

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

其中,ChromeDriver发起的 chrome 会话使用的Flash是:

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

由于上述原因,ChromeDriver启动的Google Chrome比普通的Google Chrome更轻,内存消耗更少。


推荐阅读