fix: PDF export broken in Docker and Serverless (Vercel) environments - #890
Open
ramanujamgond wants to merge 2 commits into
Open
fix: PDF export broken in Docker and Serverless (Vercel) environments#890ramanujamgond wants to merge 2 commits into
ramanujamgond wants to merge 2 commits into
Conversation
Fixes joemccann#885 ## Problem PDF export fails in Docker with the error: "Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted" This occurs because: 1. The `launch_options` was incorrectly passed as an array instead of an object (md-to-pdf expects Puppeteer's launch options format) 2. Docker's default security profile blocks Chromium's namespace creation needed for sandboxing ## Solution ### plugins/core/server.js - Fixed `launch_options` to use correct object format instead of array - Added `executablePath` to use PUPPETEER_EXECUTABLE_PATH env var - Added critical Chrome flags for containerized environments: - `--no-sandbox` - Disable Chrome sandbox - `--disable-setuid-sandbox` - Disable setuid sandbox - `--disable-dev-shm-usage` - Overcome /dev/shm size issues - `--disable-gpu` - Disable GPU hardware acceleration - `--single-process` - Run in single process mode - `--no-zygote` - Disable zygote process forking ### docker-compose.yml - Added `security_opt: seccomp=unconfined` to disable seccomp filtering - Added `cap_add: SYS_ADMIN` capability for namespace operations ## Note on Production (dillinger.io) The production site appears to run on a serverless/sandboxed environment (path shows `/home/sbx_user1051/`). Serverless platforms like Vercel have significant limitations with Puppeteer due to function size limits and missing Chrome dependencies. For production, consider: - Using @sparticuz/chromium for serverless environments - Self-hosting Chromium binary - Using a remote browser service like browserless.io
|
@ramanujamgond is attempting to deploy a commit to the Joe McCann's projects Team on Vercel. A member of the Team first needs to authorize it. |
This commit extends the PDF export fix to support both Docker and serverless environments (Vercel, AWS Lambda, etc.) Changes: - Add @sparticuz/chromium dependency for serverless Chromium support - Implement smart environment detection in markdown2Pdf function - If @sparticuz/chromium is available, use serverless-optimized config - Otherwise, fall back to Docker/traditional server configuration This fixes: - Docker: "Failed to move to new namespace" error - Vercel: "Could not find Chrome" error (issue joemccann#885) The code automatically detects the environment: - Serverless (Vercel/Lambda): Uses @sparticuz/chromium executable - Docker/Server: Uses system Chromium with sandbox-disabled flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #885 - PDF export broken on dillinger.io
This PR fixes the PDF export functionality that fails in both Docker and serverless (Vercel/AWS Lambda) environments.
Issues Addressed
Docker Environment Error
Serverless (Vercel) Environment Error
Root Cause Analysis
1. Incorrect
launch_optionsFormatThe
md-to-pdflibrary expectslaunch_optionsto be an object matching Puppeteer's launch options format, but it was incorrectly passed as an array.2. Docker Security Restrictions
Docker's default seccomp profile blocks the system calls that Chromium needs to create namespaces for its sandbox.
3. Serverless Chrome Missing
Serverless platforms like Vercel don't have Chrome pre-installed. The standard Puppeteer package tries to find Chrome in a cache directory that doesn't exist in these environments.
Changes Made
plugins/core/server.js@sparticuz/chromium@sparticuz/chromiumfor Vercel/Lambda environmentspackage.json@sparticuz/chromium: ^131.0.0dependency for serverless Chrome supportdocker-compose.ymlsecurity_opt: seccomp=unconfined- Disables seccomp filteringcap_add: SYS_ADMIN- Grants capability for namespace operationsValidation
This fix has been validated against multiple sources:
Testing
Docker
Vercel
The
@sparticuz/chromiumpackage is automatically detected and used when deployed to Vercel.Note for Maintainers
If Vercel deployment still has issues, you may need to:
libnss3.soor other dependencies are missing (may require custom build)