剧作家 - Chromium 在 node_modules 时无法启动(Azure 函数 - Linux 和 Windows)

Playwright - Can't launch Chromium when it's in node_modules (Azure Function - Linux and Windows)

我制作了一个使用 Playwright 的 Azure Function。它在本地工作,嗯,那部分没有改变)

然后我创建了 Azure DevOps 管道,所以它使用 Ubuntu 代理,用 PLAYWRIGHT_BROWSERS_PATH=0 构建它,所以 Chromium 下载到 node_modules(我在那里看到它)。然后发布到 Linux Azure Functions。

但是当函数在 Azure 中运行时,这一行:

  const crBrowser = await chromium.launch({
    executablePath:
      "./node_modules/playwright-chromium/.local-browsers/chromium-827102/chrome-linux/chrome",
  });

抛出此错误:

Error: spawn ./node_modules/playwright-chromium/.local-browsers/chromium-827102/chrome-linux/chrome EACCES =========================== logs =========================== ./node_modules/playwright-chromium/.local-browsers/chromium-827102/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-JZVt2S --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-startup-window ============================================================

我用 Windows 和 Linux 试过了 - 同样的事情,只是措辞不同。

Anthony Chu(评论中提到的那篇文章的作者,也是让我首先尝试这篇文章的作者)回答说他无法让它与 playwright-sharp 一起工作。它仅适用于 puppeteer-sharp。