Skip to content

Commit cbb48dc

Browse files
committed
added kostyl for page resource disposal during page.close
1 parent f597d09 commit cbb48dc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

playwright/page.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,22 @@ async def screenshot(
559559
async def title(self) -> str:
560560
return await self._main_frame.title()
561561

562+
# async def close(self, runBeforeUnload: bool = None) -> None:
563+
# await self._channel.send("close", locals_to_params(locals()))
564+
# if self._owned_context:
565+
# await self._owned_context.close()
566+
562567
async def close(self, runBeforeUnload: bool = None) -> None:
563568
await self._channel.send("close", locals_to_params(locals()))
564569
if self._owned_context:
565570
await self._owned_context.close()
571+
self._dispose()
572+
573+
def _dispose(self) -> None:
574+
objs_to_remove = ['Response', 'Request', 'ElementHandle', 'Frame', 'ConsoleMessage', 'JSHandle']
575+
for k in tuple(filter(lambda k: any(o in k for o in objs_to_remove), self._connection._objects)):
576+
self._connection._objects[k]._dispose()
577+
super()._dispose()
566578

567579
def isClosed(self) -> bool:
568580
return self._is_closed

0 commit comments

Comments
 (0)