错误:gpu_process_transport_factory.cc(1007)-丢失 UI 共享上下文:在无头模式下通过 ChromeDriver 初始化 Chrome 浏览器时 [英] ERROR:gpu_process_transport_factory.cc(1007)-Lost UI shared context : while initializing Chrome browser through ChromeDriver in Headless mode

查看:42
本文介绍了错误:gpu_process_transport_factory.cc(1007)-丢失 UI 共享上下文:在无头模式下通过 ChromeDriver 初始化 Chrome 浏览器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 3 台计算机中的 2 台上运行代码时出现此错误:

[0502/155335.565:ERROR:gpu_process_transport_factory.cc(1007)] 丢失 UI 共享上下文.

代码如下:

from selenium import webdriver从 selenium.webdriver.chrome.options 导入选项导入操作系统chrome_options = 选项()chrome_options.add_argument("--headless")chrome_options.add_argument("--disable-gpu")chrome_options.add_argument("--window-size=1920x1080")chrome_driver = os.getcwd() + "\chromedriver.exe"打印chrome 驱动程序:"+ chrome_driver驱动程序 = webdriver.Chrome(chrome_options=chrome_options,可执行文件路径=chrome_driver)driver.get("http://www.google.com")luck_button = driver.find_element_by_css_selector("[name=btnI")运气按钮.click()driver.get_screenshot_as_file("capture.png")

现在我检查了所有系统,它们运行的​​是 windows 10 64 位、google chrome 64 位版本:66.0.3359.139、python 2.7 32 位、chromedriver.exe 32 位、pycharm 2018.1.1

有趣的是,如果我在没有无头选项的情况下运行它,那么一切正常.浏览器弹出,我感觉很幸运按钮被按下,然后截屏.仅当我添加无头位时才会出现此错误.

我不确定当其他系统运行相同的软件时,在 1 个系统上有什么不同会允许它工作.

解决方案

Headless Chrome 首次由 Google 团队发布为 GA(通用版) 文章 无头 Chrome 入门 提到:

--disable-gpu  # 如果在 Windows 上运行,暂时需要.

一个注释被添加为:

<块引用>

现在,如果您在 Windows 上运行,您还需要包含 --disable-gpu 标志.

根据讨论 无头:制作 --disable-gpu flag 不必要 很明显:

<块引用>

LinuxMac OSX 上不再需要 --disable-gpu 标志.一旦出现错误 SwiftShader 在无头模式下的 Windows 上断言失败 已修复.

幕后发生了什么?

根据讨论 headless:从osmesa 到 SwiftShader,因为 Google/Chromium 团队决定将 SwiftShaderChrome 一起发布,该团队认为开始使用它来渲染<Headless Mode 中的 em>GL 内容.这需要进行以下几项更改:

  • Headless Mode 中跳过 GPU 数据收集,因为 SwiftShader 不被该代码视为软件实现,这会导致我们尝试从 Headless Mode 检索信息时失败strong>窗口系统.
  • 如果我们打算使用 osmesa,则仅跳过 InitializeStaticEGLInternal 中的 GL 初始化.SwiftShader 需要像其他非软件实现一样进行初始化.
  • SwiftShader 目前在 Mac OSX 上不受支持,因此团队决定在 Headless 模式下继续使用物理 GPU 在该平台上(与在其他平台上一切都由软件呈现)不同.
  • 因此,为了在 Headless Mode 中禁用 WebGL 支持,他们决定使用 --disable-gpu--disable-软件光栅化器

在无头中支持 WebGL 的想法 仍在讨论中,但 SwiftShader 在无头模式下的 Windows 上断言失败,错误如下:

[0117/125830.649194:ERROR:gpu_process_transport_factory.cc(1043)] 丢失 UI 共享上下文.DevTools 监听 ws://127.0.0.1:37429/devtools/browser/1f0b2bf7-dfdd-44ac-9da7-f2659d352f0d

结论

此错误不会影响您的@Test,您可以暂时忽略该错误.

I am getting this error when I attempt to run code on 2 of 3 computers:

[0502/155335.565:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.

Here is the code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")

chrome_driver = os.getcwd() + "\chromedriver.exe"
print "chrome driver:" + chrome_driver

driver = webdriver.Chrome(chrome_options=chrome_options, 
executable_path=chrome_driver)

driver.get("http://www.google.com")

luck_button = driver.find_element_by_css_selector("[name=btnI")
luck_button.click()

driver.get_screenshot_as_file("capture.png")

Now I have checked all of the systems, they are running windows 10 64-bit, google chrome 64 bit Version: 66.0.3359.139, python 2.7 32-bit, chromedriver.exe 32-bit, pycharm 2018.1.1

funny thing is if I run this without the headless options then everything works. The browser pops up, the I'm feeling lucky button is pressed, and a screen shot is taken. Only if I add in the headless bit does this error occur.

I am not sure what could be different on 1 system that would allow this to work when the other systems are running the same software.

解决方案

When Headless Chrome was first released as GA (General Availability) by Google Team the article Getting Started with Headless Chrome mentioned that :

--disable-gpu                 # Temporarily needed if running on Windows.

A note was added as :

Right now, you'll also want to include the --disable-gpu flag if you're running on Windows.

As per the discussion Headless: make --disable-gpu flag unnecessary it was clear that :

The --disable-gpu flag is no longer necessary on Linux or Mac OSX. It will also become unnecessary on Windows as soon as the bug SwiftShader fails an assert on Windows in headless mode is fixed.

What happened under the hood?

As per the discussion headless: Switch from osmesa to SwiftShader as Google/Chromium team decided to ship SwiftShader with Chrome the team thought to start using it to render GL content in Headless Mode. This required a couple of changes as follows :

  • Skip GPU data collection in Headless Mode since SwiftShader isn't considered a software implementation by that code which lead to a failure when we tried to retrieve information from the Window System.
  • Only skip GL initialization in InitializeStaticEGLInternal if we intend to use osmesa. SwiftShader requires initialization like the other non-software implementations.
  • SwiftShader is currently not supported on Mac OSX, so the team decided to continue to use the physical GPU in Headless Mode on that platform (unlike on other platforms where everything is software rendered).
  • So, to disable WebGL support in Headless Mode they decided to use --disable-gpu and --disable-software-rasterizer

The idea to Support WebGL in headless is still under discussion but SwiftShader fails an assert on Windows in headless mode with an error as :

[0117/125830.649194:ERROR:gpu_process_transport_factory.cc(1043)] Lost UI shared context.
DevTools listening on ws://127.0.0.1:37429/devtools/browser/1f0b2bf7-dfdd-44ac-9da7-f2659d352f0d

Conclusion

This error doesn't impact your @Test and you can ignore the error for the time being.

这篇关于错误:gpu_process_transport_factory.cc(1007)-丢失 UI 共享上下文:在无头模式下通过 ChromeDriver 初始化 Chrome 浏览器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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