Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  92] [ 5]  / answers: 1 / hits: 5247  / 3 Years ago, wed, april 7, 2021, 12:00:00

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:UsersEtshAppDataLocalms-playwrightfirefox-1238firefoxfirefox.exe -no-remote -headless -profile C:UsersEtshAppDataLocalTempplaywright_firefoxdev_profile-aruia1 -juggler-pipe -silent
<launched> pid=8500
=========================== logs ===========================
<launching> C:UsersEtshAppDataLocalms-playwrightfirefox-1238firefoxfirefox.exe -no-remote -headless -profile C:UsersEtshAppDataLocalTempplaywright_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:Projectssnkrs-playnode_modulesplaywrightlibutilsstackTrace.js:48:19)
at Connection.sendMessageToServer (D:Projectssnkrs-playnode_modulesplaywrightlibclientconnection.js:69:48)
at Proxy.<anonymous> (D:Projectssnkrs-playnode_modulesplaywrightlibclientchannelOwner.js:64:61)
at D:Projectssnkrs-playnode_modulesplaywrightlibclientbrowserType.js:64:67
at BrowserType._wrapApiCall (D:Projectssnkrs-playnode_modulesplaywrightlibclientchannelOwner.js:77:34)
at BrowserType.launch (D:Projectssnkrs-playnode_modulesplaywrightlibclientbrowserType.js:55:21)
at D:Projectssnkrs-playindex.js:4:35
at Object.<anonymous> (D:Projectssnkrs-playindex.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


More From » node.js

 Answers
4

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:Projectssnkrs-playnode_modulesplaywrightlibutilsstackTrace.js:48:19)
at Connection.sendMessageToServer (D:Projectssnkrs-playnode_modulesplaywrightlibclientconnection.js:69:48)
at Proxy.<anonymous> (D:Projectssnkrs-playnode_modulesplaywrightlibclientchannelOwner.js:64:61)
at D:Projectssnkrs-playnode_modulesplaywrightlibclientbrowserType.js:64:67
at BrowserType._wrapApiCall (D:Projectssnkrs-playnode_modulesplaywrightlibclientchannelOwner.js:77:34)
at BrowserType.launch (D:Projectssnkrs-playnode_modulesplaywrightlibclientbrowserType.js:55:21)
at D:Projectssnkrs-playindex.js:4:35
at Object.<anonymous> (D:Projectssnkrs-playindex.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.


[#1512] Saturday, April 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cadendericki

Total Points: 482
Total Questions: 109
Total Answers: 103

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;