直到昨天为止都运行良好。 完整设置是 Google Cloud Run 中 Docker 容器中 Express 中的 Playwright。最好是头脑清醒,但在这个阶段我会接受任何事情。
browserType.launch: Executable doesn't exist at /home/.cache/ms-playwright/chromium-1124/chrome-linux/chrome
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers: ║
║ ║
║ npx playwright install ║
║ ║
║ <3 Playwright Team ║
╚═════════════════════════════════════════════════════════════════════════╝
我原来的 Dockerfile:
# Start from a base Node.js image
FROM node:latest
# Install necessary packages: XVFB and fonts
RUN apt-get update \
&& apt-get install -y \
xvfb \
x11-xkb-utils \
xfonts-100dpi \
xfonts-75dpi \
xfonts-scalable \
x11-apps \
clang \
libdbus-1-3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libatspi2.0-0 \
libxcomposite1 \
libxdamage1 \
libgbm1 \
libxkbcommon0 \
libasound2 \
&& apt-get clean
# Set display environment variable for XVFB
ENV DISPLAY=:99
# Create a working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Install Playwright browsers
RUN npx playwright install
# Copy the rest of the application code
COPY . .
# Expose the port your app runs on
EXPOSE 3000
# Run XVFB, then start your Express application
CMD xvfb-run --server-args="-screen 0 1024x768x24" node index.js
package.json:“剧作家”:“^1.44.1”
index.js:
const { chromium } = require('playwright');
const browser = await chromium.launch({ headless: false });
我已经尝试过:
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD 1 ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium-browser 工作目录 /usr/src/app 复制 --chown=chrome package.json package-lock.json ./ 运行 npm 安装 入口点 ["tini", "--"]`
使用节点:14.10
executablePath = 'usr/bin/chromium-browser'
以及许多其他细微的变化。
好吧,在尝试了所有在线解决方案 3 天并尝试了 puppeteer 之后,我决定自己解决这个问题。
我在 Google 的 Chromium 浏览器快照 (chrome-linux.zip)
下载了 linux x64 chromium我将解压的文件夹添加到代码库中。
我将浏览器初始化更新为:
const 浏览器 = 等待 chromium.launch({ 可执行路径:'./chrome-linux/chrome', 无头:假 });