Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol error (Target.createTarget): browserContextId. from Node docker #478

Open
johnico opened this issue Sep 2, 2021 · 0 comments
Open

Comments

@johnico
Copy link

johnico commented Sep 2, 2021

I got this error while running a simple test from Docker file
this works great when i running it locally
did not manage to find what am I missing ?

My Dockerfile :

FROM node:14-slim

RUN  apt-get update \
     && apt-get install -y wget gnupg ca-certificates jq \
     && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
     && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
     && apt-get update \
     # We install Chrome to get all the OS level dependencies, but Chrome itself
     # is not actually used as it's packaged in the node puppeteer library.
     # Alternatively, we could could include the entire dep list ourselves
     # (https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
     # but that seems too easy to get out of date.
     && apt-get install -y google-chrome-stable \
     && rm -rf /var/lib/apt/lists/* \
     && wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
     && chmod +x /usr/sbin/wait-for-it.sh \
     && wget https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64.deb && \
     dpkg -i dumb-init_*.deb && rm -f dumb-init_*.deb \
     && apt-get clean && apt-get autoremove -y && rm -rf /var/lib/apt/lists/*


RUN apt-get update && \
apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 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 \
fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils


WORKDIR /app


RUN npm install pm2 -g

# Install Puppeteer under /node_modules so it's available system-wide
COPY package.json .
COPY package-lock.json .
RUN npm install
COPY . .
RUN npx tsc
# ENTRYPOINT ["/usr/bin/dumb-init", "--"]
ENTRYPOINT ["dumb-init", "--"]
CMD "pm2-runtime process.yml"

pdf_1    | Error: Protocol error (Target.createTarget): browserContextId
pdf_1    |     at /app/node_modules/puppeteer/src/common/Connection.ts:102:57
pdf_1    |     at new Promise (<anonymous>)
pdf_1    |     at Connection.send (/app/node_modules/puppeteer/src/common/Connection.ts:101:12)
pdf_1    |     at Browser._createPageInContext (/app/node_modules/puppeteer/src/common/Browser.ts:432:49)
pdf_1    |     at BrowserContext.newPage (/app/node_modules/puppeteer/src/common/Browser.ts:760:26)
pdf_1    |     at AppService.create (/app/src/app.service.ts:23:44)
pdf_1    |     at AppController.getInvoicePdfByUUID (/app/src/app.controller.ts:21:39)
pdf_1    |     at /app/node_modules/@nestjs/core/router/router-execution-context.js:38:29
pdf_1    |     at processTicksAndRejections (internal/process/task_queues.js:97:5)
pdf_1    |     at /app/node_modules/@nestjs/core/router/router-execution-context.js:46:28
pdf_1    |     at /app/node_modules/@nestjs/core/router/router-proxy.js:9:17

Code :

import { Injectable } from '@nestjs/common';
import { InjectContext } from 'nest-puppeteer';
// import { BrowserContext } from 'puppeteer';
import * as puppeteer from 'puppeteer';
import { ConfigService, LoggerService } from './core';

@Injectable()
export class AppService {
  constructor(
    private readonly config: ConfigService,
    private readonly logger: LoggerService,
    @InjectContext('BrowserInstanceName') private readonly browserContext: puppeteer.BrowserContext
  ) {}

  async create() {
    const page = await this.browserContext.newPage();
    await page.goto('https://google.com', {
      waitUntil: 'networkidle0',
    });

    const pdf = await page.pdf({ format: 'a4' });

    await this.browserContext.close();
    return pdf;
    // return buffer;
  }
}


from app module :

PuppeteerModule.forRoot(
      /* @ts-ignore */
      {
        pipe: true,
        /* @ts-ignore */
        headless: true,
        ignoreHTTPSErrors: true,
        args: ['--disable-setuid-sandbox', '--no-sandbox'],
      }, // optional, any Puppeteer launch options here or leave empty for good defaults */,
      'BrowserInstanceName' // optional, can be useful for using Chrome and Firefox in the same project
    ),



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant