I gave up, and decided to try using a Dockerfile to build instead.
That seems to have worked - I can see it properly installing the browsers and system dependencies for Playwright during the build.
However, Playwright itself hangs at its own launch/browser launch:
import { chromium } from "playwright";
export async function scrapeWithPlaywright(url) {
console.log("Playwright initiated...");
const browser = await chromium.launch({
channel: "chromium",
headless: true, // Ensure headless mode
args: ["--no-sandbox", "--disable-setuid-sandbox"], // Fix permissions inside Docker
});
const page = await browser.newPage();
console.log(`Playwrighting to ${url}...`);
It never reaches the second console.log, so clearly it is having trouble launching Chrome.
For reference, my Dockerfile is this:
FROM node:20-bookworm
# Set working directory inside container
WORKDIR /app
# Copy package.json and package-lock.json separately for better caching
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy all remaining files
COPY . .
# Install Playwright dependencies
RUN npx -y playwright@1.50.1 install --with-deps chromium
# Expose 8000
EXPOSE 8000
# Start the app
CMD ["node", "app.js"]
But I don’t think that’s the problem - I am guessing it’s some kind of koyeb/docker/arguments issue