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

Improving the stealth mode a bit for Playwright

Karim shoair28b783e86bc6
diff --git a/scrapling/engines/constants.py b/scrapling/engines/constants.py
index 245e5c0..926e238 100644
--- a/scrapling/engines/constants.py
+++ b/scrapling/engines/constants.py
@@ -44,7 +44,7 @@ DEFAULT_STEALTH_FLAGS = [
'--disable-default-apps',
'--disable-print-preview',
'--disable-dev-shm-usage',
- '--disable-popup-blocking',
+ # '--disable-popup-blocking',
'--metrics-recording-only',
'--disable-crash-reporter',
'--disable-partial-raster',
diff --git a/scrapling/engines/pw.py b/scrapling/engines/pw.py
index 3f6a187..818720b 100644
--- a/scrapling/engines/pw.py
+++ b/scrapling/engines/pw.py
@@ -90,6 +90,14 @@ class PlaywrightEngine:
self.nstbrowser_mode = bool(nstbrowser_mode)
self.nstbrowser_config = nstbrowser_config
self.adaptor_arguments = adaptor_arguments if adaptor_arguments else {}
+ self.harmful_default_args = [
+ # This will be ignored to avoid detection more and possibly avoid the popup crashing bug abuse: https://issues.chromium.org/issues/340836884
+ '--enable-automation',
+ '--disable-popup-blocking',
+ # '--disable-component-update',
+ # '--disable-default-apps',
+ # '--disable-extensions',
+ ]
def _cdp_url_logic(self, flags: Optional[List] = None) -> str:
"""Constructs new CDP URL if NSTBrowser is enabled otherwise return CDP URL as it is
@@ -154,10 +162,10 @@ class PlaywrightEngine:
else:
if self.stealth:
browser = p.chromium.launch(
- headless=self.headless, args=flags, ignore_default_args=['--enable-automation'], chromium_sandbox=True, channel='chrome' if self.real_chrome else 'chromium'
+ headless=self.headless, args=flags, ignore_default_args=self.harmful_default_args, chromium_sandbox=True, channel='chrome' if self.real_chrome else 'chromium'
)
else:
- browser = p.chromium.launch(headless=self.headless, ignore_default_args=['--enable-automation'], channel='chrome' if self.real_chrome else 'chromium')
+ browser = p.chromium.launch(headless=self.headless, ignore_default_args=self.harmful_default_args, channel='chrome' if self.real_chrome else 'chromium')
# Creating the context
if self.stealth: