如何在Ubuntu上使用Chrome的“硬件加速”和“WebGL”?

huangapple go评论98阅读模式
英文:

How to use chrome 'Hardware acceleration' and 'webgl' at Ubuntu?

问题

Ubuntu 版本: 18.04.5,无 GUI
Chrome 版本: 110.0.5481.177
我想要: 使用 Selenium(Python)使用 Chrome 进行爬虫
但是,当我爬取必须爬取的网站时,会出现以下错误信息
> 嗯。虽然您的浏览器似乎支持 WebGL,但它被禁用或不可用。如果可能的话,请确保您的显卡驱动程序是最新的。
要获取更多帮助,请点击此链接。
查看以下链接以了解更多关于 WebGL 以及查找更多使用 WebGL 的 web 应用程序。
WebGL Wiki
需要更多关于 WebGL 的信息吗?
khronos.org/webgl
由 Digital Ocean 托管
并且,当我通过 Selenium 访问 chrome://gpu 时,会出现以下错误信息。
> 图形功能状态
Canvas: 仅软件。硬件加速已禁用
Canvas 进程外光栅化: 已禁用
直接渲染显示合成器: 已禁用
合成: 仅软件。硬件加速已禁用
多个光栅线程: 已启用
OpenGL: 已禁用
光栅化: 仅软件。硬件加速已禁用
原始绘制: 已禁用
视频解码: 仅软件。硬件加速已禁用
视频编码: 仅软件。硬件加速已禁用
Vulkan: 已禁用
WebGL: 已禁用
WebGL2: 已禁用
WebGPU: 已禁用
检测到的问题
WebGPU 已通过阻止列表或命令行禁用。
禁用功能:webgpu
已禁用加速视频编码,无论是通过阻止列表、about:flags 还是命令行。
禁用功能:video_encode
已禁用 GPU 合成,无论是通过阻止列表、about:flags 还是命令行。浏览器将退回到软件合成,硬件加速将不可用。
禁用功能:gpu_compositing
版本信息
导出的数据
2023-03-07T05:13:27.125Z
Chrome 版本
HeadlessChrome/110.0.5481.177
操作系统
Linux 4.15.0-163-generic
软件渲染列表 URL
https://chromium.googlesource.com/chromium/src/+/f34f7ab2d4ca4ad498ef42aeba4f4eb2c1392d63/gpu/config/software_rendering_list.json
在观察了上述两个错误消息之后,我认为这是一个“硬件加速”和“WebGL”问题。
因此,我尝试了多次启用“硬件加速”和“WebGL”,但没有成功。以下是我尝试的方法。
vi /usr/share/applications/google-chrome.desktop
在编辑之后,将
Exec=/opt/google/chrome/google-chrome-stable %U
更改为 Exec=/opt/google/chrome/google-chrome-stable -–ignore-gpu-blacklist –-enable-webgl -–flag-switches-begin –flag-switches-end %U 等等。
(我认为它可能没有应用,因为我不知道如何在 Linux 环境中重新启动 Chrome。)
感谢阅读。

英文:

Ubuntu version : 18.04.5 and without gui
chrome version : 110.0.5481.177
I want : Using chrome to crawling with Selenium(python)
But, If I crawl to the site where I have to crawl, An error message occurs like below
<br><br><br>
>Hmm. While your browser seems to support WebGL, it is disabled or unavailable. If possible, please ensure that you are running the latest drivers for your video card.
For more help, please click this link.
Check out some of the following links to learn more about WebGL and to find more web applications using WebGL.
<br><br>
WebGL Wiki
Want more information about WebGL?
<br><br>
khronos.org/webgl
Hosted by Digital Ocean

And, When I approach chrome://gpu through the selenium, the following error message appears.

> Graphics Feature Status
Canvas: Software only. Hardware acceleration disabled
Canvas out-of-process rasterization: Disabled
Direct Rendering Display Compositor: Disabled
Compositing: Software only. Hardware acceleration disabled
Multiple Raster Threads: Enabled
OpenGL: Disabled
Rasterization: Software only. Hardware acceleration disabled
Raw Draw: Disabled
Video Decode: Software only. Hardware acceleration disabled
Video Encode: Software only. Hardware acceleration disabled
Vulkan: Disabled
WebGL: Disabled
WebGL2: Disabled
WebGPU: Disabled
Problems Detected
WebGPU has been disabled via blocklist or the command line.
Disabled Features: webgpu
Accelerated video encode has been disabled, either via blocklist, about:flags or the command line.
Disabled Features: video_encode
Gpu compositing has been disabled, either via blocklist, about:flags or the command line. The browser will fall back to software compositing and hardware acceleration will be unavailable.
Disabled Features: gpu_compositing
Version Information
Data exported
2023-03-07T05:13:27.125Z
Chrome version
HeadlessChrome/110.0.5481.177
Operating system
Linux 4.15.0-163-generic
Software rendering list URL
https://chromium.googlesource.com/chromium/src/+/f34f7ab2d4ca4ad498ef42aeba4f4eb2c1392d63/gpu/config/software_rendering_list.json
...

After observing the above two error messages, I think it is a 'Hardware acceleration' and 'webgl' problem.

So, I have tried to enable 'Hardware acceleration' and 'webgl' several times, but it does not work. Below is the method I tried.

vi /usr/share/applications/google-chrome.desktop
after
edit
from Exec=/opt/google/chrome/google-chrome-stable %U
to Exec=/opt/google/chrome/google-chrome-stable -–ignore-gpu-blacklist –-enable-webgl -–flag-switches-begin –flag-switches-end %U etc..
(I think it might not have been applied because I don't know how to restart Chrome in a Linux environment.)
<br><br>
Thanks for reading

答案1

得分: 1

为了确保你的参数正确传递,请尝试使用以下脚本:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--ignore-gpu-blacklist")
options.add_argument("--enable-webgl")
options.add_argument("--disable-gpu")
driver = webdriver.Chrome(chrome_options=options)

如果仍然不起作用,请随时评论,我将编辑我的答案。

资源链接

英文:

To make sure your arguments get passed correctly, try using the following script:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument(&quot;-ignore-gpu-blacklist&quot;)
options.add_argument(&quot;-enable-webgl&quot;)
options.add_argument(&quot;--disable-gpu&quot;)
driver = webdriver.Chrome(chrome_options=options)

If this still doesn't work, feel free to comment, and I'll edit my answer.

resource

huangapple
  • 本文由 发表于 2023年3月7日 15:11:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定