From b5a248707e2b5ff75681a082a93135373d874ecb Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Fri, 24 Jan 2025 21:19:29 +0200 Subject: [PATCH 1/4] Small performance boost on ip validation with caching --- pythonlib/camoufox/ip.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pythonlib/camoufox/ip.py b/pythonlib/camoufox/ip.py index b1dc976..1b60672 100644 --- a/pythonlib/camoufox/ip.py +++ b/pythonlib/camoufox/ip.py @@ -62,10 +62,12 @@ class Proxy: } +@lru_cache(128, typed=True) def valid_ipv4(ip: str) -> bool: return bool(re.match(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$', ip)) +@lru_cache(128, typed=True) def valid_ipv6(ip: str) -> bool: return bool(re.match(r'^(([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4})$', ip)) From 6fc8ee287e49f67a958fe02a88770d08fa8417f1 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Fri, 24 Jan 2025 21:21:27 +0200 Subject: [PATCH 2/4] Make `Geolocation` frozen to use less memory And it can be cached later if that intended in the future --- pythonlib/camoufox/locale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonlib/camoufox/locale.py b/pythonlib/camoufox/locale.py index 173b986..7a0662a 100644 --- a/pythonlib/camoufox/locale.py +++ b/pythonlib/camoufox/locale.py @@ -61,7 +61,7 @@ class Locale: return data -@dataclass +@dataclass(frozen=True) class Geolocation: """ Stores geolocation information. From 499fcd5442cd3fdcda83f3492d4ae8886d4108a8 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Fri, 24 Jan 2025 21:23:25 +0200 Subject: [PATCH 3/4] Enable clipboard Events Websites can check if clipboard events are turned off, this hurts stealth --- settings/camoufox.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/settings/camoufox.cfg b/settings/camoufox.cfg index 5cb5bbd..924a6c4 100644 --- a/settings/camoufox.cfg +++ b/settings/camoufox.cfg @@ -341,9 +341,6 @@ defaultPref("browser.toolbars.bookmarks.visibility", "never"); // Do not reopen windows on startup defaultPref("privacy.clearOnShutdown.openWindows", true); -// Clipboard -defaultPref("dom.event.clipboardevents.enabled", false); // disable user triggered clipboard access - // Fingerprinting defaultPref("privacy.resistFingerprinting", false); // This will actually hurt fingerprinting. // defaultPref("privacy.resistFingerprinting.block_mozAddonManager", true); // prevents rfp from breaking AMO From e01c2d6476147ce6978a606b47dbd9b9a6dcfcc9 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Fri, 24 Jan 2025 21:30:09 +0200 Subject: [PATCH 4/4] Increase process count for perfomance boost while keeping it a realistic number Using 16 is to balance process isolation and resource use as using 60000 as PlayWright is impractical and may cause instability. --- settings/camoufox.cfg | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/settings/camoufox.cfg b/settings/camoufox.cfg index 924a6c4..0a9ade0 100644 --- a/settings/camoufox.cfg +++ b/settings/camoufox.cfg @@ -455,10 +455,9 @@ defaultPref("network.cookie.cookieBehavior", 4); // issue we can povide custom '@mozilla.org/ipc/processselector;1' // defaultPref("dom.ipc.processCount", 60000); -// Dear Playwright devs, -// YES! This does cause a significant performance hit! -// Camoufox will be keeping this at 1 for the foreseeable future. -defaultPref("dom.ipc.processCount", 1); +// Using 16 is to balance process isolation and resource usage +// The 60000 PlayWright is using is impractical and may cause instability. +defaultPref("dom.ipc.processCount", 16); // Never reuse processes as they may keep previously overridden values // (locale, timezone etc.).