I run 300 asyncio tasks, with multiple browsers contexts that visit pages at the same time. Sometimes I get this error which causes everything to crash. From what I understand, this is either a memory leak or just not having enough resources available. I am not sure whether it is a memory leak caused by me, since there is not much I am doing on my side (just visiting webpages, and yes, I do close pages after visit is completed). What happens if there is a memory leak in the JavaScript code executed by visiting one of the web pages? Is there a way to make Playwright avoid letting a webpage consume all the resources?
[240854:0x6785e40] 1640109 ms: Mark-sweep 4016.8 (4131.1) -> 4004.4 (4131.8) MB, 2680.4 / 0.4 ms (average mu = 0.086, current mu = 0.041) task; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xb7a940 node::Abort() [/home/Traffic/venv/lib/python3.10/site-packages/playwright/driver/node] (...)
This thread is trying to answer question "How can one avoid the 'JavaScript heap out of memory' error when running multiple asyncio tasks with browser contexts in Playwright?"
Hello, I am getting a similar error on the version 139.0
<--- Last few GCs --->
[22:0x67ad560] 89435467 ms: Scavenge 4037.8 (4120.4) -> 4037.3 (4131.2) MB, 5.8 / 0.0 ms (average mu = 0.968, current mu = 0.213) allocation failure;
[22:0x67ad560] 89435488 ms: Scavenge 4044.5 (4131.2) -> 4043.5 (4132.4) MB, 6.8 / 0.0 ms (average mu = 0.968, current mu = 0.213) allocation failure;
[22:0x67ad560] 89436176 ms: Scavenge 4045.4 (4132.4) -> 4044.4 (4153.2) MB, 683.0 / 0.0 ms (average mu = 0.968, current mu = 0.213) allocation failure;
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1: 0xb87bc0 node::Abort() [/usr/local/lib/python3.9/site-packages/playwright/driver/node]
Aborted (core dumped)
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].