• Uncategorized

About linux : Puppeteer-in-Docker-not-loading-web-fonts

Question Detail

When running Puppeteer inside Docker, some external font-face fonts are not loaded.

As an example, when accessing https://misli.com and intercepting resources requests through page.on('request') shows that the font files are never requested. However, when running puppeteer directly in local OSX (outside Docker), the fonts are correctly downloaded.

See example Puppeteer script:

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({
      headless: true,
      args: ['--ignore-certificate-errors','--no-sandbox','--disable-setuid-sandbox']
    })
    const page = await browser.newPage()

    await page.setRequestInterception(true)
    page.on('request', async (request) => {
        if(request.resourceType() == 'font'){
            console.log(request.url())
        }   
        await request.continue()
    })
    
    await page.goto('https://misli.com/',  {waitUntil : "networkidle2"})
    await page.evaluateHandle('document.fonts.ready')
    await browser.close()
})()

And the output outside Docker (inside Docker the output is blank):

https://st.misli.com/build/fonts/barlow-v5-latin-ext_latin-regular.af51b9c.woff2
https://st.misli.com/build/fonts/barlow-v5-latin-ext_latin-600.fe20152.woff2
https://st.misli.com/build/fonts/barlow-v5-latin-ext_latin-500.d9d4d40.woff2
https://st.misli.com/build/fonts/barlow-v5-latin-ext_latin-700.6a5f5c7.woff2
https://st.misli.com/build/fonts/barlow-v5-latin-ext_latin-800.6a6ccfb.woff2

See here the Dockerfile:

FROM node:12

ENV DEBIAN_FRONTEND noninteractive
ARG REQUIREMENTS_FILE
RUN apt-get update
RUN apt-get install -y build-essential \
                        screen \
                        less \
                        vim \
                        xmlsec1 \
                        libx11-xcb1 \
                        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\
                        ca-certificates\
                        fonts-liberation\
                        libappindicator1\
                        libnss3\
                        lsb-release\
                        xdg-utils\
                        wget\
                        libgconf-2-4\
                        libgbm-dev\
                        xfonts-utils

RUN 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 \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
  --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*


RUN rm -rf /var/lib/apt/lists/*t

ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

ADD --chown=node:node ./ /home/node/app
WORKDIR /home/node/app

USER node
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
ENV NODE_PATH=/home/node/app/node_modules

RUN npm install
RUN npm install run-func supervisor forever -g

EXPOSE 3000
ENTRYPOINT ["dumb-init", "--"]
# CMD ["node", "server.js"]
CMD ["forever","server.js"]

Is there anything missing in the Docker definition?

Question Answer

No answer for now.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.