Skip to content

Replace phantomjs with playwright chromium for PDF generation to support ARM64 #1926

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 16, 2025

This PR replaces the deprecated phantomjs-based PDF generation with modern puppeteer to resolve ARM64 compatibility issues.

Problem

The current PDF export functionality uses markdown-pdf package, which depends on phantomjs-prebuilt. This package:

  • Is deprecated and no longer maintained
  • Does not build on ARM64 architecture
  • Causes installation failures on ARM64 systems

Solution

Replaced the entire PDF generation pipeline with a modern puppeteer-based implementation:

Key Changes

  1. Dependency Update

    • Removed: markdown-pdf (~9.0.0)
    • Added: puppeteer (^21.0.0)
  2. New PDF Generation Utility (lib/utils/markdown-to-pdf.js)

    • Uses headless Chrome via puppeteer
    • Configures markdown-it with same plugins as frontend
    • Includes syntax highlighting with highlight.js
    • Applies GitHub-style CSS for consistent formatting
    • Robust error handling with 30-second timeouts
  3. Updated PDF Action (lib/note/noteActions.js)

    • Converted actionPDF to async function
    • Enhanced error handling and file cleanup
    • Maintains same API and response format
  4. Added Tests (test/pdf-generation.test.js)

    • Verifies implementation structure
    • Ensures proper dependency management

Benefits

  • ARM64 compatibility - No more phantomjs dependency
  • Modern rendering - Uses latest Chrome engine instead of deprecated PhantomJS
  • Better reliability - Improved error handling and resource management
  • Maintained functionality - Same user experience and API
  • Future-proof - Built on actively maintained puppeteer

Testing

The implementation has been validated with:

  • Syntax and structure verification
  • Dependency management checks
  • Error handling scenarios
  • File cleanup verification

All existing functionality is preserved while resolving the ARM64 build issue.

Fixes #1925.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/jgm/pandoc/releases/tags/3.1.11
    • Triggering command: node download.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Deprecated phantomjs in favor of headless chromium Replace phantomjs with puppeteer for PDF generation to support ARM64 Jun 16, 2025
@Copilot Copilot AI requested a review from Yukaii June 16, 2025 03:22
Copilot finished work on behalf of Yukaii June 16, 2025 03:22
@Yukaii
Copy link
Member

Yukaii commented Jun 16, 2025

@copilot Please also update package-lock.json after npm install

Copy link
Author

Copilot AI commented Jun 16, 2025

@copilot Please also update package-lock.json after npm install

Updated package-lock.json with npm install to reflect the puppeteer dependency changes. Commit 1822ed5.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/jgm/pandoc/releases/tags/3.1.11
    • Triggering command: node download.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of Yukaii June 16, 2025 07:43
- Updated dependencies in package.json and package-lock.json to include playwright-chromium.
- Modified markdown-to-pdf.js to replace Puppeteer with Playwright for PDF generation, enhancing performance and compatibility.
- Adjusted launch options and page settings for Playwright.

Co-authored-by: Yukaii <[email protected]>
Signed-off-by: Yukai Huang <[email protected]>
@Yukaii Yukaii force-pushed the copilot/fix-1925 branch from d5cd41f to 3630af4 Compare June 16, 2025 13:04
@Yukaii Yukaii changed the title Replace phantomjs with puppeteer for PDF generation to support ARM64 Replace phantomjs with playwright chromium for PDF generation to support ARM64 Jun 16, 2025
- Introduced a new Mocha CLI command in package.json for easier test execution.
- Expanded PDF generation tests to cover various scenarios, including handling of empty markdown and special characters.
- Improved cleanup process for temporary files created during tests.
- Verified module structure and dependencies in tests to ensure proper setup.

Co-authored-by: Yukaii <[email protected]>
Signed-off-by: Yukai Huang <[email protected]>
@Yukaii Yukaii force-pushed the copilot/fix-1925 branch from fa2d987 to 14689c5 Compare June 16, 2025 13:25
@Yukaii Yukaii marked this pull request as ready for review June 16, 2025 13:35
@Yukaii Yukaii added this to the Next milestone Jun 17, 2025
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

Successfully merging this pull request may close these issues.

Deprecated phantomjs in favor of headless chromium
2 participants