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(StealthySession): Close persistent context default page

Karim shoairf298b76b8e80
diff --git a/scrapling/engines/_browsers/_camoufox.py b/scrapling/engines/_browsers/_camoufox.py
index 44d8735..5afccb1 100644
--- a/scrapling/engines/_browsers/_camoufox.py
+++ b/scrapling/engines/_browsers/_camoufox.py
@@ -251,6 +251,11 @@ class StealthySession:
**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)
@@ -580,6 +585,11 @@ class AsyncStealthySession(StealthySession):
**self.launch_options
)
)
+
+ # 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)