How to deploy Nodejs PlayWright (installing deps for chromium)?

I’m trying to install Playwright with a barebones node (lts) setup. With an index file like below

index.js


const { chromium } = require("playwright-chromium");

(async () => {
  const browser = await chromium.launch({ chromiumSandbox: false });
  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('http://whatsmyuseragent.org/');
  await browser.close();
})();

My package.json contains the playwright version below, so npm install should work.
"playwright": "^1.21.1",

And then the build/run commands below

npm install && npx playwright install --with-deps chromium
npm run start // node index.js

However, I always get an error browserType.launch: Executable doesn't exist at /opt/render/.cache/ms-playwright/chromium-1000/chrome-linux/chrome That is playwright dependenacies and chromium won’t install properly.

For Heroku, you’d need a Playwright build back.

Has anyone gotten playwright to work with render properly?

Getting an error

Cannot install dependencies for this linux distribution!

Is the only solution to use a docker file?

Hi there,

Thanks for reaching out.

Our native environments don’t current support installing OS-level packages, for that you would need to use Docker to setup your own environment.

There does seem to be a feature request on our feedback site for adding the ability to install packages: https://feedback.render.com/features/p/allow-custom-packages-to-be-installed. Please feel free to upvote/comment.

Kind regards

Alan

Damn, I feared that might be the case. Messing around with docker always takes forever.

In case some other poor soul needs to use Node + Playwright, dockerfile worked for me.

# Build Environment: Node + Playwright
FROM node:16
FROM mcr.microsoft.com/playwright:focal

# Env
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH

# Export port 3000 for Node
EXPOSE 3000

# Copy all app files into Docker Work directory
COPY package*.json /app/
COPY index.ts /app/
COPY src/ /app/src/
COPY tsconfig.json /app/

# Install Deps
RUN npm install

# Build TS into JS to run via Node
RUN npm run build

# Run Node index.js file
CMD [ "npm", "start" ]