Skip to content

Conversation

@iloveitaly
Copy link
Collaborator

No description provided.

Add a new example project demonstrating Playwright usage with Node.js. This
example mirrors the existing Puppeteer example but uses Playwright instead:

- Opens a headless Chromium browser
- Navigates to Hacker News
- Logs browser version and navigation steps
- Includes test.json for integration testing
Add a Python example demonstrating Playwright usage. This example mirrors the
existing Node.js Playwright example but uses Python's sync_playwright API:

- Launches a headless Chromium browser
- Navigates to Hacker News
- Logs browser version and navigation steps
- Uses pyproject.toml for dependency management
- Includes test.json for integration testing
- Remove README files from both examples
- Update version pins to use minor versions only (^1.49 instead of ^1.49.1)
- Add mise.toml files to ensure latest versions:
  - node-playwright: node and pnpm latest
  - python-playwright: python and uv latest
- Remove readme reference from python pyproject.toml
- Add pnpm-lock.yaml for node-playwright example
- Add uv.lock for python-playwright example
Add automatic detection and installation of Playwright browsers for both
Python and Node.js projects:

**Python provider:**
- Detect playwright dependency in all package managers (uv, pip, poetry,
  pdm, pipenv)
- Run `playwright install --with-deps` after package installation
- Installs browser binaries and system dependencies

**Node.js provider:**
- Add `usesPlaywright()` method to detect playwright dependency
- Run `npx playwright install --with-deps` after npm install
- Add runtime apt packages for playwright (similar to puppeteer)
- Ensures browser dependencies are available in the final image

The `--with-deps` flag handles both browser binary installation and
system dependencies, ensuring Playwright works out of the box.
Improve Playwright installation by using the install-deps command
instead of --with-deps flag for more explicit dependency management.

**Changes:**

**Node.js provider:**
- Add ExecCommand() method to PackageManager to get correct exec command
  (pnpm exec, npx, bunx) for each package manager
- Split Playwright installation into two commands:
  - `playwright install` - installs browser binaries
  - `playwright install-deps` - installs system dependencies
- Remove manual runtime apt packages for Playwright (install-deps handles this)

**Python provider:**
- Split installation into separate commands for all package managers:
  - `playwright install` - installs browser binaries
  - `playwright install-deps` - installs system dependencies
- Applied to uv, pip, poetry, pdm, and pipenv

This approach is more explicit and allows install-deps to properly
handle system dependencies on its own, removing the need for manual
apt package management.
Improve Python Playwright setup for better performance and control:

**Changes:**
- Install only chromium browser instead of all browsers (firefox, webkit, chromium)
  using `playwright install chromium`
- Remove `playwright install-deps` script to avoid extra package installation
- Add Playwright runtime dependencies manually to pythonRuntimeDepRequirements:
  - libglib2.0-0, libatk1.0-0, libatk-bridge2.0-0
  - libcups2, libxkbcommon0, libatspi2.0-0
  - libxcomposite1, libxdamage1, libxfixes3, libxrandr2
  - libgbm1, libcairo2, libpango-1.0-0, libasound2

This approach:
- Reduces image size by only installing chromium
- Uses Railpack's apt package management instead of Playwright's install script
- Maintains consistent dependency handling with other Python packages
Add clarifying comments for Playwright installation:

**Clarifications:**
- Document that playwright install code appears in each package manager
  function but only ONE runs per build (not multiple times)
- Explain that 'playwright install chromium' only installs chromium browser
- Note that chromium runs in headless mode when launched with headless=True
  in code (no separate headless installation needed)

**Apt package source documentation:**
- Add comment explaining where to find latest Playwright apt dependencies:
  - Run `playwright install-deps chromium` to see apt-get output
  - Check https://github.com/microsoft/playwright/blob/main/packages/playwright-core/browsers.json
- This helps maintainers update the package list when Playwright updates

These comments help future maintainers understand the implementation choices
and how to keep dependencies up to date.
Fix issue where Playwright browsers were being installed during the install
step but not persisted to the final deploy stage, causing runtime errors.

**Problem:**
- `playwright install chromium` downloads browsers to /root/.cache/ms-playwright
- Install step only returned VENV_PATH, so browser cache was not included
- Deploy stage couldn't find browsers, causing "Executable doesn't exist" error

**Solution:**
- Add PLAYWRIGHT_CACHE_DIR constant (/root/.cache/ms-playwright)
- Modify all Install* functions (uv, pip, poetry, pdm, pipenv) to return
  both VENV_PATH and PLAYWRIGHT_CACHE_DIR when playwright is detected
- This ensures browser binaries are included in installArtifacts layer
- Deploy stage now has access to downloaded browsers

The browser cache is only included in outputs when playwright dependency
is detected, keeping images small for non-Playwright projects.
Add libnspr4 and libnss3 to Python Playwright runtime dependencies.
These packages are required for Chromium to run properly.

**Error encountered:**
- Playwright showed: "Host system is missing dependencies to run browsers"
- Suggested installing: libnspr4 and libnss3

**Fix:**
Added the missing packages to pythonRuntimeDepRequirements["playwright"]

Now the complete list includes all required dependencies for Chromium to
run in headless mode.
Apply same optimization approach to Node.js as Python - install only
chromium and use manual apt package management instead of install-deps.

**Changes:**

**Installation:**
- Change from `playwright install` to `playwright install chromium`
  - Only installs chromium browser (not firefox/webkit)
  - Reduces image size significantly
- Remove `playwright install-deps` command
  - Avoid running Playwright's apt installation script
  - Use Railpack's apt package management instead

**Runtime dependencies:**
- Add Playwright runtime apt packages manually:
  - libglib2.0-0, libatk1.0-0, libatk-bridge2.0-0
  - libcups2, libxkbcommon0, libatspi2.0-0
  - libxcomposite1, libxdamage1, libxfixes3, libxrandr2
  - libgbm1, libcairo2, libpango-1.0-0, libasound2
  - libnspr4, libnss3
- Document where to find the latest package list

**Cache persistence:**
- Add PLAYWRIGHT_CACHE_DIR constant (/root/.cache/ms-playwright)
- Browser cache already persisted via existing /root/.cache inclusion
  in buildIncludeDirs

This approach matches the Python implementation and provides better
control over dependencies while reducing image size.
Fix error: "error while loading shared libraries: libatomic.so.1: cannot
open shared object file: No such file or directory"

**Problem:**
- Node.js 25+ requires libatomic1 at runtime
- The library was missing from the runtime apt packages
- This caused Node.js to fail to start

**Solution:**
Add libatomic1 to the base runtime apt packages for all Node.js projects.
This ensures newer Node.js versions (25+) can run properly.

Note: This is a Node.js requirement, not specific to Playwright or Puppeteer.
Switch from `playwright install chromium` to `playwright install --only-shell`
for both Python and Node.js providers.

**What changed:**
- Python (all package managers): Use `playwright install --only-shell`
- Node.js: Use `playwright install --only-shell`

**Benefits:**
- Installs chromium_headless_shell instead of full chromium browser
- Smaller image size - headless shell is optimized for server environments
- No GUI components needed
- Faster installation

The --only-shell flag specifically installs the headless shell variant which is
purpose-built for headless browser automation, making it ideal for CI/CD and
production server environments.
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.

2 participants