Issue with JSReport in Docker: 'Failed to launch the browser process!' Error



  • Hi everyone,

    I'm having trouble running JSReport in a Docker container. I keep getting the following error:

    ERROR [ExceptionsHandler] Failed to launch the browser process! undefined
    [74:74:0130/095024.337607:ERROR:zygote_host_impl_linux.cc(101)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
    Error: Failed to launch the browser process! undefined
    2025-01-30 09:50:24 [74:74:0130/095024.337607:ERROR:zygote_host_impl_linux.cc(101)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
    

    I have already added the --no-sandbox and --disable-dev-shm-usage flags in my template configuration, but the issue persists.

    My setup:

    • Node.js version: 22.13.1

    • NestJS version: 10

    • JSReport setup:

       * ``` @jsreport/jsreport-core 
       * ``` @jsreport/jsreport-handlebars 
       * ``` @jsreport/jsreport-chrome-pdf
       * ``` @jsreport/jsreport-pdf-utils 
       * ``` @jsreport/jsreport-assets 
       * ``` @jsreport/jsreport-scripts
       * ``` @jsreport/jsreport-fs-store
      

    Dockerfile

    FROM node:22.13.1
    
    # GET HOUR ZONE
    ENV TZ=America/Tegucigalpa
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    RUN apt-get clean && apt-get update && apt-get install -y locales
    RUN locale-gen en_US.UTF-8
    ENV LANG en_US.UTF-8
    ENV LANGUAGE en_US:en
    ENV LC_ALL en_US.UTF-8
    
    
    RUN apt-get update && \
        apt-get upgrade -y && \
        apt-get install -y --no-install-recommends \
            software-properties-common \
            wget \
            gnupg \
            git \
            curl \
            make \
            build-essential \
            gconf-service \
            libgbm-dev \
            libdrm2 \
            libatk-bridge2.0-0 \
            libxkbcommon0 \
            libatspi2.0-0 \
            libasound2 \
            libatk1.0-0 \
            libc6 \
            libcairo2 \
            libcups2 \
            libdbus-1-3 \
            libexpat1 \
            libfontconfig1 \
            libgcc1 \
            libgconf-2-4 \
            libappindicator3-1 \
            libgdk-pixbuf2.0-0 \
            libglib2.0-0 \
            libgtk-3-0 \
            libnspr4 \
            libpango-1.0-0 \
            libpangocairo-1.0-0 \
            libstdc++6 \
            libx11-6 \
            libx11-xcb1 \
            libxcb1 \
            libxcomposite1 \
            libxcursor1 \
            libxdamage1 \
            libxext6 \
            libxfixes3 \
            libxi6 \
            libxrandr2 \
            libxrender1 \
            libxss1 \
            libxtst6 \
            ca-certificates \
            fonts-liberation \
            libappindicator1 \
            libnss3 \
            lsb-release \
            xdg-utils && \
        curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
        echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
        apt-get update && \
        apt-get install -y --no-install-recommends google-chrome-stable && \
        apt-get clean && \
        rm -rf /var/lib/apt/lists/*
    
    # Install fonts and necessary packages
    RUN apt-get update && apt-get install -y \
        fontconfig \
        fonts-dejavu-core \
        ttf-mscorefonts-installer \
        --no-install-recommends
    
    # Set the working directory
    WORKDIR /PatmedServiceReport/src/app
    
    # Copy package.json and package-lock.json
    COPY package*.json ./
    
    # Install dependencies
    RUN npm install
    
    # Install Playwright and browsers
    RUN npx playwright install
    
    # Copy the rest of the application files
    COPY . .
    
    # Build the application
    RUN npm run build
    
    # Expose the necessary port
    EXPOSE 3333
    
    # Set the entry point for the container
    CMD [ "node", "dist/main" ]
    

    Template configuration

    chrome: {
        marginTop: '15px',
        marginBottom: '90px',
        format: 'Letter',
        printBackground: true,
        launchOptions: {
            args: ["--no-sandbox", "--disable-dev-shm-usage"]
        }
    }
    

    Service using JSReport

    import { Injectable, OnModuleInit } from '@nestjs/common';
    import * as JsReport from '@jsreport/jsreport-core';
    import * as JsReportHandlebars from '@jsreport/jsreport-handlebars';
    import * as JsReportChromePdf from '@jsreport/jsreport-chrome-pdf';
    import * as JsReportPdfUtils from '@jsreport/jsreport-pdf-utils';
    import * as JsReportAssets from '@jsreport/jsreport-assets';
    import * as JsReportScripts from '@jsreport/jsreport-scripts';
    import * as JsReportFSStore from '@jsreport/jsreport-fs-store';
    
    @Injectable()
    export class ReportService implements OnModuleInit {
      private jsreport: any;
    
      async onModuleInit() {
        this.jsreport = JsReport();
    
        // Registrar extensiones
        this.jsreport.use(JsReportHandlebars());
        this.jsreport.use(JsReportChromePdf());
        this.jsreport.use(JsReportPdfUtils());
        this.jsreport.use(JsReportAssets());
        this.jsreport.use(JsReportScripts());
        this.jsreport.use(JsReportFSStore());
        
        await this.jsreport.init();
      }
    
      async generateReport(template: any, data: any) {
        const response = await this.jsreport.render({
          template,
          data,
        });
        return response.content;
      }
    }
    

    Also I tried this, but doesnt work chrome-pdf

    engine: 'handlebars',
                recipe: 'chrome-pdf',
                content: templateHtml,
                helpers: readFileSync(
                    join(__dirname, '..', '..', '..', 'views/solicitudes/helpers.js'),
                    'utf8'
                ),
                chrome: {
                    marginTop: '15px',
                    marginBottom: '90px',
                    marginLeft: '0',
                    marginRight: '0',
                    format: 'Letter',
                    printBackground: true
                },
                "extensions": {
                    "chrome-pdf": {
                        "launchOptions": {
                            "args": ['--no-sandbox', '--disable-setuid-sandbox']
                        }
                    }
                },
                pdfOperations:
    

    I've tried several things, but I still get the error about the browser process failing to launch.

    Does anyone know what might be causing this issue? Could it be related to how the Chrome browser is installed in my Docker container? demo stackblitz for download

    Please help, I want to deploy this in a development environment to show a demo of the library to my bosses, but I don't know how to fix this.



  • I found the solution! It turns out the issue was that the launch options needed to be set in the library.

    Here's the working code:

    this.jsreport.use(JsReportChromePdf({
      launchOptions: {
        headless: true,
        args: ["--no-sandbox", "--disable-setuid-sandbox"]
      }
    }));
    
    

    Adding launchOptions fixed the problem. Hope this helps anyone facing the same issue! Here the reference Failed to launch the browser process no usable sandbox


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.