firefox 浏览器无法在 playwright 中启动

时间:2021-04-07 11:16:19

标签: javascript node.js playwright firefox-nightly

我正在使用 playwright 使用 Firefox 自动执行一些测试。我使用这个起始代码:

const { firefox } = require('playwright');

(async () => {
    const browser = await firefox.launch();
    // Create pages, interact with UI elements, assert values
    await browser.close();
})();

但它无法执行。这是记录的错误:

(node:756) UnhandledPromiseRejectionWarning: browserType.launch: Protocol error (Browser.enable): Browser closed.
==================== Browser output: ====================
<launching> C:\Users\Etsh\AppData\Local\ms-playwright\firefox-1238\firefox\firefox.exe -no-remote -headless -profile C:\Users\Etsh\AppData\Local\Temp\playwright_firefoxdev_profile-aruia1 -juggler-pipe -silent
<launched> pid=8500
=========================== logs ===========================
<launching> C:\Users\Etsh\AppData\Local\ms-playwright\firefox-1238\firefox\firefox.exe -no-remote -headless -profile C:\Users\Etsh\AppData\Local\Temp\playwright_firefoxdev_profile-aruia1 -juggler-pipe -silent
<launched> pid=8500
============================================================
Note: use DEBUG=pw:api environment variable to capture Playwright logs.
Error
    at Object.captureStackTrace (D:\Projects\snkrs-play\node_modules\playwright\lib\utils\stackTrace.js:48:19)
    at Connection.sendMessageToServer (D:\Projects\snkrs-play\node_modules\playwright\lib\client\connection.js:69:48)
    at Proxy.<anonymous> (D:\Projects\snkrs-play\node_modules\playwright\lib\client\channelOwner.js:64:61)
    at D:\Projects\snkrs-play\node_modules\playwright\lib\client\browserType.js:64:67
    at BrowserType._wrapApiCall (D:\Projects\snkrs-play\node_modules\playwright\lib\client\channelOwner.js:77:34)
    at BrowserType.launch (D:\Projects\snkrs-play\node_modules\playwright\lib\client\browserType.js:55:21)
    at D:\Projects\snkrs-play\index.js:4:35
    at Object.<anonymous> (D:\Projects\snkrs-play\index.js:7:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:756) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我将这个变量 DEBUG=pw 包含在一个 .env 文件中,以便它记录剧作家的日志,我认为前几个日志是剧作家的。 然后我尝试打开已安装的 Firefox 以检查它是否有效并且确实有效。这是构建的屏幕截图: firefox build

1 个答案:

答案 0 :(得分:1)

我发现了错误。这是因为一些缺少的库需要。当我将 playwright 降级到 1.9 版并运行代码时我发现了这一点,然后这是错误消息:

(node:12876) UnhandledPromiseRejectionWarning: browserType.launch: Host system is missing dependencies!

Some of the Universal C Runtime files cannot be found on the system. You can fix
that by installing Microsoft Visual C++ Redistributable for Visual Studio from:
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

Full list of missing libraries:
    vcruntime140.dll
    msvcp140.dll
Error
    at Object.captureStackTrace (D:\Projects\snkrs-play\node_modules\playwright\lib\utils\stackTrace.js:48:19)
    at Connection.sendMessageToServer (D:\Projects\snkrs-play\node_modules\playwright\lib\client\connection.js:69:48)
    at Proxy.<anonymous> (D:\Projects\snkrs-play\node_modules\playwright\lib\client\channelOwner.js:64:61)
    at D:\Projects\snkrs-play\node_modules\playwright\lib\client\browserType.js:64:67
    at BrowserType._wrapApiCall (D:\Projects\snkrs-play\node_modules\playwright\lib\client\channelOwner.js:77:34)
    at BrowserType.launch (D:\Projects\snkrs-play\node_modules\playwright\lib\client\browserType.js:55:21)
    at D:\Projects\snkrs-play\index.js:4:35
    at Object.<anonymous> (D:\Projects\snkrs-play\index.js:7:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12876) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12876) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

提供了缺失库的列表。分期付款成功后,firefox 运行良好。我再次升级到 1.10 版,firefox 仍然有效。