我正在嘗試運行一個簡單的 Azure 函數,該函數將根據瀏覽器中的可見內容進入頁面并生成 PDF。我創建了一個 NodeJS 12 Azure Function with Linux Consumption Plan (B1)。我設置PLAYWRIGHT_BROWSERS_PATH為0。函數代碼如下所示:const { chromium } = require("playwright-chromium");const baseUrl = "http://someurl";const targetPage = "/action/";module.exports = async function (context, req) { const browser = await chromium.launch(); const page = await browser.newPage(); console.log (baseUrl + targetPage + context.bindingData.id) await page.goto(baseUrl + targetPage + context.bindingData.id, { waitUntil: 'domcontentloaded' }); await page.emulateMedia({ media: 'print' }); onst result = await page.pdf({ printBackground: true, format: 'letter' }); context.res = { body: result, headers: { 'Content-Type': "application/pdf" } }; await page.close(); await browser.close();};包.json{ "name": "", "version": "", "scripts": { "start": "func start", "test": "echo \"No tests yet...\"" }, "description": "", "devDependencies": {}, "dependencies": { "playwright-chromium": "1.3.0" }}和函數.json{ "bindings": [ { "authLevel": "anonymous", "type": "httpTrigger", "direction": "in", "name": "req", "methods": [ "get" ], "route": "route/{id}" }, { "type": "http", "direction": "out", "name": "res" } ]}當我檢查應用洞察時,我發現有以下錯誤:Exception while executing function: Functions.PDF Result: FailureException: Worker was unable to load function PDF: 'Error: Cannot find module 'playwright-chromium'Require stack:- /home/site/wwwroot/PDF/index.js- /azure-functions-host/workers/node/worker-bundle.js- /azure-functions-host/workers/node/dist/src/nodejsWorker.js'Stack: Error: Cannot find module 'playwright-chromium'
在 Azure Functions 中運行 Playwright
莫回無
2023-03-10 13:42:17