Skip to content

🕷️ The BEST Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev

perf(DynamicSession): Close persistent context default page

Karim shoair710f994339df
diff --git a/scrapling/engines/_browsers/_controllers.py b/scrapling/engines/_browsers/_controllers.py
index 2747ed9..85db198 100644
--- a/scrapling/engines/_browsers/_controllers.py
+++ b/scrapling/engines/_browsers/_controllers.py
@@ -248,6 +248,10 @@ class DynamicSession:
user_data_dir="", **self.launch_options
)
+ # Get the default page and close it
+ default_page = self.context.pages[0]
+ default_page.close()
+
if self.init_script: # pragma: no cover
self.context.add_init_script(path=self.init_script)
@@ -505,6 +509,10 @@ class AsyncDynamicSession(DynamicSession):
)
)
+ # Get the default page and close it
+ default_page = self.context.pages[0]
+ await default_page.close()
+
if self.init_script: # pragma: no cover
await self.context.add_init_script(path=self.init_script)