From f6ef52a39be62a084de5fbe58253e34360085d4b Mon Sep 17 00:00:00 2001 From: daijro Date: Tue, 3 Dec 2024 22:50:50 -0600 Subject: [PATCH] pythonlib: Support for main world evaluation 0.4.5 --- pythonlib/camoufox/__version__.py | 2 +- pythonlib/camoufox/utils.py | 8 ++++++++ pythonlib/pyproject.toml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pythonlib/camoufox/__version__.py b/pythonlib/camoufox/__version__.py index ff41fb9..14e4f38 100644 --- a/pythonlib/camoufox/__version__.py +++ b/pythonlib/camoufox/__version__.py @@ -8,7 +8,7 @@ class CONSTRAINTS: The minimum and maximum supported versions of the Camoufox browser. """ - MIN_VERSION = 'beta.17' + MIN_VERSION = 'beta.18' MAX_VERSION = '1' @staticmethod diff --git a/pythonlib/camoufox/utils.py b/pythonlib/camoufox/utils.py index 7f49b80..e5c2eed 100644 --- a/pythonlib/camoufox/utils.py +++ b/pythonlib/camoufox/utils.py @@ -354,6 +354,7 @@ def launch_options( fingerprint: Optional[Fingerprint] = None, ff_version: Optional[int] = None, headless: Optional[bool] = None, + main_world_eval: Optional[bool] = None, executable_path: Optional[Union[str, Path]] = None, firefox_user_prefs: Optional[Dict[str, Any]] = None, proxy: Optional[Dict[str, str]] = None, @@ -416,6 +417,9 @@ def launch_options( Whether to run the browser in headless mode. Defaults to False. Note: If you are running linux, passing headless='virtual' to Camoufox & AsyncCamoufox will use Xvfb. + main_world_eval (Optional[bool]): + Whether to enable running scripts in the main world. + To use this, prepend "mw:" to the script: page.evaluate("mw:" + script). executable_path (Optional[Union[str, Path]]): Custom Camoufox browser executable path. firefox_user_prefs (Optional[Dict[str, Any]]): @@ -574,6 +578,10 @@ def launch_options( if isinstance(humanize, (int, float)): set_into(config, 'humanize:maxTime', humanize) + # Enable the main world context creation + if main_world_eval: + set_into(config, 'allowMainWorld', True) + # Set Firefox user preferences if block_images: firefox_user_prefs['permissions.default.image'] = 2 diff --git a/pythonlib/pyproject.toml b/pythonlib/pyproject.toml index c0ca55d..a594bb4 100644 --- a/pythonlib/pyproject.toml +++ b/pythonlib/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "camoufox" -version = "0.4.4" +version = "0.4.5" description = "Wrapper around Playwright to help launch Camoufox" authors = ["daijro "] license = "MIT"