I'm trying to print html to pdf using headless chromium (using puppeteer) and everything works fine except if html contains large png images (over 10.000x10.000px) the whole process of rendering page takes extremely long (up to half an hour, but if using non-headless mode it takes only about 10 seconds). After days of investigating and tweaking I came to conclusion that this must be issue with page compositing process.
Below are dumps from chrome://gpu
page in headless and non-headless modes.
Only significant difference i've noticed is that, when runing chrome headlessly, puppeteer appends by itself --disable-gpu-compositing
and --allow-pre-commit-input
which i believe are responsible for dramatic performace dropdown.
Also, in non-headless mode chrome sees 2 gpu units:
GPU0 VENDOR= 0x10de, DEVICE=0x1d01 *ACTIVE*
GPU1 VENDOR= 0x8086, DEVICE=0x1912
and in headless mode only one:
GPU0 VENDOR= 0xffff [Google Inc.], DEVICE=0xffff [Google SwiftShader] *ACTIVE*
which is CPU-based implementation of the Vulkan and OpenGL ES graphics APIs.
So basicaly my question is:
Is there any way to run headless chrome/chromium with puppeteer using actual gpu (especialy for gpu-compositing), or is there any way to print page to pdf in non-headless mode?
Here is my non-headless chrome gpu config (where page rendering is fast):
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
And here is headless chrome gpu config (which is extemely slow)
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
Even if i added --disable-webgl
and --disable-webgl2
still
VENDOR= 0xffff [Google Inc.], DEVICE=0xffff [Google SwiftShader] *ACTIVE*
is being used.
Additionally:
Gpu compositing has been disabled, either via blacklist, about:flags or the command line. The browser will fall back to software compositing and hardware acceleration will be unavailable. Disabled Features: gpu_compositing WebGL has been disabled via blacklist or the command line. Disabled Features: webgl WebGL2 has been disabled via blacklist or the command line. Disabled Features: webgl2
notice appears on chrome://gpu
page
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: 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