Issue
I have a node script which converts a webpage into a PDF document. The user enters some content and PHP builds a HTML page, which then is used in a node script (that runs Puppeteer, using a slightly modified version of an example script) to convert it to PDF.
But when I exec in PHP the command to run the node script, it fails with the following error:
(node:14832) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
[0424/165455.239499:ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data received.
[0424/165455.239717:FATAL:content_main_delegate.cc(53)] Check failed: false.
#0 0x55f27f255b0c base::debug::StackTrace::StackTrace()
#1 0x55f27f26e780 logging::LogMessage::~LogMessage()
#2 0x55f27d5f7d23 content::ContentMainDelegate::TerminateForFatalInitializationError()
#3 0x55f27ef90deb content::ContentMainRunnerImpl::Initialize()
#4 0x55f27ef9ab72 service_manager::Main()
#5 0x55f27ef8ff14 content::ContentMain()
#6 0x55f28309f9b9 headless::(anonymous namespace)::RunContentMain()
#7 0x55f28309fa42 headless::HeadlessBrowserMain()
#8 0x55f27ef97f9d headless::HeadlessShellMain()
#9 0x55f27d5f61ac ChromeMain
#10 0x7efcaad45c05 __libc_start_main
#11 0x55f27d5f602a _start
PHP is running with the apache
user. However, if I run the same script with my user, it works perfectly. When I execute in a terminal using su - apache -c 'node ...'
it again throws the error described above.
What is causing the error? Something related to apache user's permissions? I've followed all troubleshotting guides but I had no luck at the moment.
Solution
The problem seems to come from the file-system permissions on the default chromium used by puppeteer:
using ACL( my nginx group is www-data
, change with yours for apache):
sudo setfacl -R -m g:www-data:rX node_modules/puppeteer/.local-chromium/
and
sudo setfacl -dR -m g:www-data:rX node_modules/puppeteer/.local-chromium/
after setting the permissions the error went away.
Answered By - jeandel Answer Checked By - David Marino (WPSolving Volunteer)