启用硬件加速器,以与剧作家一起使用无头铬
我目前正在使用GitHub动作,剧作家和无头铬的组合进行一些E2E测试。现在,目前我的测试需要一段时间(简单测试的数十秒钟),这不是理想的,尤其是因为我的用例需要经常进行此类测试。经过一番研究,我发现了许多人似乎都提到的链接: https://michelkraemer.com/enable-gpu-for-slow-playwright-tests-tests-in-headless-mode/
它提供了有关如何启用GPU硬件加速度的指令。但是,无论我做什么硬件加速度,都拒绝在无头模式下启用。在头部模式下,默认情况下实际上启用了它,并且一切运行更顺畅。这是我的代码:
(async () => {
let browser = await chromium.launch({
args: ['--use-gl=desktop', '--use-angle=default'],
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('chrome://gpu');
await page.pdf({
path: 'page.pdf',
});
})();
我已经尝试了- use-gl = egl
也无济于事。每次,PDF仅显示软件,硬件加速度都不可用
。在这一点上,我怀疑笔记本电脑的硬件可能是某个问题,但我不知道如何找到它。我还确认我的命令行args实际上是由剧作家传递的,因为使用- 窗口大小
确实更改了窗口大小,- disable-software-stastization
似乎确实禁用了一些事情。
更新:' - use-gl = swiftshader'对我没有改变。此外,我相信我的问题在于“ - ignore-gpu-blocklist”,因为即使我包括在内,这个标志仍在残障,这使我相信某些东西正在迫使我的GPU不提供硬件加速度。如果有帮助,我的笔记本电脑的GPU是NVIDIA 2060,尽管当我的代码通过GitHub操作远程运行时,我的代码也无法正常工作。
这是chrome的结果:// gpu
as-is: htttps:// pastebin .com/u6m0pcjy
这是添加之后的结果 - disable-software-rasterization
: https:// pastebin。 com/udfquqqQ
任何帮助将不胜感激!
I'm currently working on some E2E tests using a combination of Github Actions, Playwright, and headless Chromium. Now, currently my tests take quite a while (tens of seconds for simple tests) which is not ideal, especially seeing as my use-case requires lots of these tests to be run pretty often. After some research, I discovered this link that many people seem to refer to: https://michelkraemer.com/enable-gpu-for-slow-playwright-tests-in-headless-mode/
It provides instructions for how to enable GPU hardware acceleration for slow Playwright tests in headless mode. However, no matter what I do hardware acceleration refuses to be enabled in headless mode. In headed mode, it is actually enabled by default and everything runs smoother. Here's my code:
(async () => {
let browser = await chromium.launch({
args: ['--use-gl=desktop', '--use-angle=default'],
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('chrome://gpu');
await page.pdf({
path: 'page.pdf',
});
})();
I've tried --use-gl=egl
as well to no avail. Every time, the pdf shows Software only, hardware acceleration unavailable
. At this point I suspect it may be some issue with my laptop's hardware but I don't know exactly how to find this out. I've also confirmed that my command-line args are actually being passed through by Playwright since using --window-size
did actually change the window size, and --disable-software-rasterization
does seem to disable some things.
Updates: '--use-gl=swiftshader' did not make a difference for me. Additionally, I believe that my issue lies somewhere with '--ignore-gpu-blocklist', since this flag is remaining disabled even when I include it, which leads me to believe that something is forcing my GPU to not provide hardware acceleration. My laptop's GPU is an Nvidia 2060 if that helps, although my code doesn't work when run remotely through a GitHub Action either.
Here's a pastebin with the results from chrome://gpu
as-is: https://pastebin.com/U6m0pcjY
Here's one with the results after adding --disable-software-rasterization
: https://pastebin.com/uDfQuqQq
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下代码吗?
我检查了,这对我有用,这是屏幕截图。
https://i.sstatic.net/1kurg.png
//i.sstatic.net/1kurg.png“ rel =” nofollow noreferrer“>
Can you try below code-
I checked and this is working for me, here is the screenshot.
https://i.sstatic.net/1kUrG.png
自从问这个问题以来已经有一段时间了,但是对于任何面临类似问题的人来说,我敢肯定那里有很多问题。
我最近与semotion.dev开源社区一起解决了相同的问题并使其起作用。我们成功地以无头模式的硬件加速运行远程。
I have consolidated my findings in a post 如何启用铬,铬&在无头模式下的AWS上的木偶。而且我相信这将提供帮助和指南,以使Chrome以硬件加速度在无头模式下工作。
免责声明:我是本指南的作者
It's been a while since this question was asked, but for anyone facing similar issues which i am sure there are many out there.
I recently worked with Remotion.dev open-source community to fix the same issue and make it work. We were successful in running Remotion with Hardware Acceleration in headless mode.
I have consolidated my findings in a post How To Enable Hardware Acceleration on Chrome, Chromium & Puppeteer on AWS in Headless mode. And I am sure this will offer help and guidelines to make Chrome work in headless mode with Hardware Acceleration.
Disclaimer: I am the author of this guide