Fix Emojis Not Rendering in Headless Chrome
In this article
Emojis not rendering in headless Chrome screenshots can cause visual inconsistencies, especially when generating images for social media, reports, or automated testing. This issue typically occurs because the default font configuration in headless Chrome lacks support for emoji glyphs. Fixing it involves ensuring the correct fonts are installed and accessible in the environment where Chrome runs, and configuring Chrome to use them. The solution works across Linux, Docker, and CI/CD environments where headless Chrome is commonly deployed.
What You'll Need
- A Linux-based system or Docker container running headless Chrome (e.g., via Puppeteer, Playwright, or Selenium)
- Root or sudo access to install system fonts (if not using Docker)
- Basic familiarity with command-line tools and package managers (apt, apk, yum)
- Chrome or Chromium installed in headless mode
Step-by-Step
- Verify emoji support in your current environment: Run a test screenshot using headless Chrome of a page containing emojis (e.g., đ, đ, â¤ď¸). If emojis appear as empty boxes, question marks, or fallback symbols, the system lacks emoji font support.
- Install emoji-capable fonts: On Debian/Ubuntu-based systems, install the
fonts-noto-color-emojipackage using the command:sudo apt-get update && sudo apt-get install -y fonts-noto-color-emoji
This installs Googleâs Noto Color Emoji font, which supports full-color emoji rendering. - For Alpine Linux (common in Docker containers): Use the apk package manager:
apk add --no-cache noto-fonts-emoji
Note: Alpine may require additional font directories to be scanned. Ensure the font is in/usr/share/fontsor/usr/local/share/fonts. - Refresh the font cache: After installing fonts, run:
fc-cache -fv
This forces the fontconfig system to re-scan available fonts and rebuild its cache, making the emoji font detectable by Chrome. - Ensure Chrome uses the correct font path: Launch headless Chrome with the
--font-render-hinting=mediumand--disable-gpuflags if not already set. More importantly, include:--no-sandbox --disable-setuid-sandbox
These are often required in containerized environments and can affect font access. - Set font fallback explicitly (optional but effective): Use Chromeâs command-line flag to prioritize emoji fonts:
--font-family="Noto Color Emoji"
Alternatively, inject CSS in your rendered page:body { font-family: 'Noto Color Emoji', sans-serif; }
This ensures emojis fall back to a supported font even if the default system font doesnât include them. - Test in a controlled HTML page: Create a minimal HTML file with visible emojis:
<html><body>Test: đđâ¤ď¸</body></html>
Take a screenshot using your headless setup. If emojis now render correctly, the fix is working. - Verify in Docker (if applicable): If using Docker, rebuild the image after installing fonts and confirm the layer includes the font package. Use
docker exec [container] fc-list | grep -i emojito verify the font is present. - Adjust container permissions if needed: In some cases, Chrome running as a non-root user may not read font files. Ensure the font directory (
/usr/share/fonts) has read permissions for all users:chmod -R a+r /usr/share/fonts - Use a known-working base image (alternative): Consider using a pre-configured image like
zenika/puppeteerorthegrohlm/puppeteer-aws-lambdathat includes emoji fonts by default.
Common Mistakes
- Skipping the font cache refresh (
fc-cache -fv), which means Chrome never detects the new font. - Assuming all Linux distributions package emoji fonts the same wayâDebian uses
fonts-noto-color-emoji, Alpine usesnoto-fonts-emoji. - Running Chrome without
--no-sandboxin containers, which can restrict access to system resources including fonts. - Forgetting to rebuild Docker images after adding font installations, leading to outdated containers.
- Using outdated versions of Chrome or Puppeteer that have known emoji rendering bugs.
Tips
- Always test emoji rendering with a variety of emoji types (skin tones, family groups, flags) to ensure full support.
- In CI/CD pipelines, cache the font installation step to avoid re-downloading on every run.
- If color emojis still donât render, check whether Chrome is running with GPU support disabledâsome emoji rendering requires GPU acceleration.
- Use Puppeteerâs
emulateMediaorsetContentwith explicit font-family CSS to force emoji font usage. - Monitor Chrome version updatesâsome versions regress emoji support, so pin to known-working versions if necessary.
Troubleshooting
If emojis still donât render after following the steps:
- Check font installation: Run
fc-list | grep -i emojito confirm the emoji font is listed. If not, reinstall the font package. - Verify file permissions: Ensure Chrome has read access to
/usr/share/fontsand subdirectories. Usels -la /usr/share/fontsto check. - Test locally first: Before deploying to CI/CD, reproduce the setup on a local machine to isolate environment issues.
- Use Chromeâs debug flags: Launch Chrome with
--enable-logging --v=1to capture logs. Look for font-related errors likeFailed to load font. - Try a different emoji font: If Noto Color Emoji doesnât work, test with
noto-fontsornoto-fonts-extrapackages. - Check container base image: Minimal images like
alpine:latestornode:slimoften lack fontconfig tools. Installfontconfigfirst before adding fonts.
Frequently Asked Questions
Why donât emojis render in headless Chrome by default?
Headless Chrome environments, especially in containers, often lack emoji fonts and fontconfig tools needed to detect and render them.
Does this work with Puppeteer or Playwright?
Yes, both tools use headless Chrome. Install fonts in the host or container environment where Chrome runs.
Do I need GPU support for emojis to render?
Not always, but GPU acceleration can improve rendering. Try without --disable-gpu if possible.
Can I use a web font instead of system fonts?
Yes, but web fonts may not render in screenshots if Chrome blocks external requests. System fonts are more reliable.
Why do emojis show as black-and-white instead of color?
Color emoji support depends on the font and Chrome version. Noto Color Emoji should render in color if properly loaded.
Will this fix work in AWS Lambda or serverless environments?
Only if you can bundle fonts with your deployment package and set font paths correctly. Use pre-built layers that include fonts.