本文介绍了强制无头铬/铬使用实际的GPU,而不是Google SwiftShader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用无头铬将html打印为pdf(使用puppeteer),一切正常,除非html包含较大的PNG图像(超过10.000x10.000px),呈现页面的整个过程需要非常长的时间(最多半小时,但如果使用非无头模式,则只需要大约10秒)。经过几天的调查和调整,我得出结论,这一定是页面合成过程有问题。
下面是无标题和非无标题模式下chrome://gpu
页中的转储。我注意到的唯一显著区别是,当无头运行Chrome时,木偶操纵者自己附加了--disable-gpu-compositing
和--allow-pre-commit-input
,我认为这是导致戏剧性性能下拉的原因。另外,在非无头模式下,Chrome可以看到2个GPU单元:
GPU0 VENDOR= 0x10de, DEVICE=0x1d01 *ACTIVE*
GPU1 VENDOR= 0x8086, DEVICE=0x1912
并且在无头模式下只有一个:
GPU0 VENDOR= 0xffff [Google Inc.], DEVICE=0xffff [Google SwiftShader] *ACTIVE*
这是Vulkan和OpenGL ES图形API的基于CPU的实现。
所以基本上我的问题是:
有没有办法使用实际的GPU(特别是GPU合成)在木偶操纵者身上运行无头铬/铬,或者有没有办法在无头模式下将页面打印到pdf?
这是我的非无头Chrome GPU配置(其中页面渲染速度很快):
Canvas: Hardware accelerated
Flash: Hardware accelerated
Flash Stage3D: Hardware accelerated
Flash Stage3D Baseline profile: Hardware accelerated
Compositing: Hardware accelerated
Multiple Raster Threads: Force enabled
Out-of-process Rasterization: Hardware accelerated
OpenGL: Enabled
Hardware Protected Video Decode: Unavailable
Rasterization: Hardware accelerated on all pages
Skia Renderer: Enabled
Video Decode: Unavailable
Vulkan: Disabled
WebGL: Hardware accelerated
WebGL2: Hardware accelerated
Chrome version: Chrome/83.0.4103.0
Operating system: Linux 4.13.0-46-generic
2D graphics backend: Skia/83 8ce842d38d0b32149e874d6855c91e8c68ba65a7
Command line:
/home/wojtas/projects/project-generator/node_modules/puppeteer/.local-
chromium/linux-756035/chrome-linux/chrome
--disable-background-networking
--enable-features=NetworkService,NetworkServiceInProcess
--disable-background-timer-throttling
--disable-backgrounding-occluded-windows
--disable-breakpad
--disable-client-side-phishing-detection
--disable-component-extensions-with-background-pages
--disable-default-apps
--disable-dev-shm-usage
--disable-extensions
--disable-features=TranslateUI
--disable-hang-monitor
--disable-ipc-flooding-protection
--disable-popup-blocking
--disable-prompt-on-repost
--disable-renderer-backgrounding
--disable-sync
--force-color-profile=srgb
--metrics-recording-only
--no-first-run
--enable-automation
--password-store=basic
--use-mock-keychain
--disable-web-security
--user-data-dir=/var/www/project-generator/var/chrome-user-data
--allow-file-access-from-files
--no-sandbox
--no-sandbox-and-elevated
--no-zygote
--enable-webgl
--use-gl=desktop
--use-skia-renderer
--enable-gpu-rasterization
--enable-zero-copy
--disable-gpu-sandbox
--enable-native-gpu-memory-buffers
--disable-background-timer-throttling
--disable-backgrounding-occluded-windows
--disable-renderer-backgrounding
--ignore-certificate-errors
--enable-hardware-overlays
--num-raster-threads=4
--default-tile-width=512
--default-tile-height=512
--enable-oop-rasterization
--remote-debugging-port=0
--flag-switches-begin
--flag-switches-end
--enable-audio-service-sandbox
这里是无头Chrome GPU配置(非常慢)
Graphics Feature Status
Canvas: Hardware accelerated
Flash: Hardware accelerated
Flash Stage3D: Hardware accelerated
Flash Stage3D Baseline profile: Hardware accelerated
Compositing: Software only. Hardware acceleration disabled
Multiple Raster Threads: Force enabled
Out-of-process Rasterization: Hardware accelerated
OpenGL: Enabled
Hardware Protected Video Decode: Unavailable
Rasterization: Hardware accelerated on all pages
Skia Renderer: Enabled
Video Decode: Unavailable
Vulkan: Disabled
WebGL: Hardware accelerated but at reduced performance
WebGL2: Hardware accelerated but at reduced performance
Chrome version: HeadlessChrome/83.0.4103.0
Operating system: Linux 4.13.0-46-generic
2D graphics backend: Skia/83 8ce842d38d0b32149e874d6855c91e8c68ba65a7
Command Line:
/home/wojtas/projects/project-generator/node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome
--disable-background-networking
--enable-features=NetworkService,NetworkServiceInProcess
--disable-background-timer-throttling
--disable-backgrounding-occluded-windows
--disable-breakpad
--disable-client-side-phishing-detection
--disable-component-extensions-with-background-pages
--disable-default-apps
--disable-dev-shm-usage
--disable-extensions
--disable-features=TranslateUI
--disable-hang-monitor
--disable-ipc-flooding-protection
--disable-popup-blocking
--disable-prompt-on-repost
--disable-renderer-backgrounding
--disable-sync
--force-color-profile=srgb
--metrics-recording-only
--no-first-run
--enable-automation
--password-store=basic
--use-mock-keychain
--headless
--hide-scrollbars
--mute-audio
--disable-web-security
--user-data-dir=/var/www/project-generator/var/chrome-user-data
--allow-file-access-from-files
--no-sandbox
--no-sandbox-and-elevated
--no-zygote
--enable-webgl
--use-gl=desktop
--use-skia-renderer
--enable-gpu-rasterization
--enable-zero-copy
--disable-gpu-sandbox
--enable-native-gpu-memory-buffers
--disable-background-timer-throttling
--disable-backgrounding-occluded-windows
--disable-renderer-backgrounding
--ignore-certificate-errors
--enable-hardware-overlays
--num-raster-threads=4
--default-tile-width=512
--default-tile-height=512
--enable-oop-rasterization
--remote-debugging-port=0
--disable-gpu-compositing
--allow-pre-commit-input
即使我添加了--disable-webgl
和--disable-webgl2
仍然VENDOR= 0xffff [Google Inc.], DEVICE=0xffff [Google SwiftShader] *ACTIVE*
正在使用。其他:
通知出现在chrome://gpu
页
图形功能状态:
Canvas: Hardware accelerated
Flash: Hardware accelerated
Flash Stage3D: Hardware accelerated
Flash Stage3D Baseline profile: Hardware accelerated
Compositing: Software only. Hardware acceleration disabled
Multiple Raster Threads: Enabled
Out-of-process Rasterization: Disabled
OpenGL: Enabled
Hardware Protected Video Decode: Unavailable
Rasterization: Hardware accelerated on all pages
Skia Renderer: Enabled
Video Decode: Unavailable
Vulkan: Disabled
WebGL: Disabled
WebGL2: Disabled
WebGL
确实需要无头模式的推荐答案吗?
如果删除此参数.
--enable-webgl
.它应该停止加载SwiftShader并坚持使用GPU。
这篇关于强制无头铬/铬使用实际的GPU,而不是Google SwiftShader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!