Search code examples
javascriptnode.jsplaywrightfirefox-nightly

firefox browser does not start in playwright


I am using playwright to automate some testing with Firefox. I use this starting code:

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

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

but it fails to execute. Here is the error that is logged:

(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.

I included this variable DEBUG=pw in a .env file so that it would log playwright logs, and I think the first few logs are playwright's. I then tried opening the installed firefox to check if it works and it does. Here is a screenshot of the build: firefox build


Solution

  • I found the error. It was because of some missing libraries need. I discovered this when I downgraded playwright to version 1.9 and ran the the code then this was the error msg:

    (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.
    

    A list of missing libraries was provided. After successful installments, firefox ran fine. I upgraded again to version 1.10 and firefox still works.