mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-02-10 23:22:04 -08:00
pythonlib: Add block_images, block_webrtc, fixes, etc. 0.1.3
- Adds block_images & block_webrtc parameters to Camoufox and AsyncCamoufox - Fixes async_api - Update README
This commit is contained in:
parent
e487754a42
commit
f18b9a00be
6 changed files with 86 additions and 43 deletions
|
|
@ -84,28 +84,34 @@ Launches a new browser instance for Camoufox.
|
|||
Accepts all Playwright Firefox launch options, along with the following:
|
||||
|
||||
Parameters:
|
||||
playwright (Playwright):
|
||||
The playwright instance to use.
|
||||
config (Optional[Dict[str, Any]]):
|
||||
The configuration to use.
|
||||
Configuration to use.
|
||||
addons (Optional[List[str]]):
|
||||
The addons to use.
|
||||
Addons to use.
|
||||
fingerprint (Optional[Fingerprint]):
|
||||
The fingerprint to use.
|
||||
BrowserForge fingerprint to use.
|
||||
exclude_addons (Optional[List[DefaultAddons]]):
|
||||
The default addons to exclude, passed as a list of camoufox.DefaultAddons enums.
|
||||
Default addons to exclude. Passed as a list of camoufox.DefaultAddons enums.
|
||||
screen (Optional[browserforge.fingerprints.Screen]):
|
||||
The screen constraints to use.
|
||||
BrowserForge screen constraints to use.
|
||||
os (Optional[ListOrString]):
|
||||
The operating system to use for the fingerprint. Either a string or a list of strings.
|
||||
Operating system to use for the fingerprint. Either a string or a list of strings.
|
||||
user_agent (Optional[ListOrString]):
|
||||
The user agent to use for the fingerprint. Either a string or a list of strings.
|
||||
User agent to use for the fingerprint. Either a string or a list of strings.
|
||||
fonts (Optional[List[str]]):
|
||||
The fonts to load into Camoufox, in addition to the default fonts.
|
||||
Fonts to load into Camoufox, in addition to the default fonts.
|
||||
args (Optional[List[str]]):
|
||||
The arguments to pass to the browser.
|
||||
Arguments to pass to the browser.
|
||||
block_images (Optional[bool]):
|
||||
Whether to block all images.
|
||||
block_webrtc (Optional[bool]):
|
||||
Whether to block WebRTC entirely.
|
||||
firefox_user_prefs (Optional[Dict[str, Any]]):
|
||||
Firefox user preferences to set.
|
||||
env (Optional[Dict[str, Union[str, float, bool]]]):
|
||||
Environment variables to set.
|
||||
executable_path (Optional[str]):
|
||||
The path to the Camoufox browser executable.
|
||||
Custom Camoufox browser executable path.
|
||||
**launch_options (Dict[str, Any]):
|
||||
Additional Firefox launch options.
|
||||
```
|
||||
|
|
@ -119,7 +125,7 @@ Parameters:
|
|||
Camoufox [config data](https://github.com/daijro/camoufox?tab=readme-ov-file#fingerprint-injection) can be passed as a dictionary to the `config` parameter:
|
||||
|
||||
```python
|
||||
from camoufox import Camoufox
|
||||
from camoufox.sync_api import Camoufox
|
||||
|
||||
with Camoufox(
|
||||
config={
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def confirm_paths(paths: List[str]) -> None:
|
|||
Confirms that the addon paths are valid
|
||||
"""
|
||||
for path in paths:
|
||||
if not os.path.exists(path):
|
||||
if not os.path.isdir(path):
|
||||
raise InvalidAddonPath(path)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ class AsyncCamoufox(PlaywrightContextManager):
|
|||
self.browser: Optional[Browser] = None
|
||||
|
||||
async def __aenter__(self) -> Browser:
|
||||
await super().__aenter__()
|
||||
self.browser = await AsyncNewBrowser(self._playwright, **self.launch_options)
|
||||
_playwright = await super().__aenter__()
|
||||
self.browser = await AsyncNewBrowser(_playwright, **self.launch_options)
|
||||
return self.browser
|
||||
|
||||
async def __aexit__(self, *args: Any):
|
||||
|
|
@ -42,6 +42,9 @@ async def AsyncNewBrowser(
|
|||
fonts: Optional[List[str]] = None,
|
||||
args: Optional[List[str]] = None,
|
||||
executable_path: Optional[str] = None,
|
||||
block_images: Optional[bool] = None,
|
||||
block_webrtc: Optional[bool] = None,
|
||||
firefox_user_prefs: Optional[Dict[str, Any]] = None,
|
||||
env: Optional[Dict[str, Union[str, float, bool]]] = None,
|
||||
**launch_options: Dict[str, Any]
|
||||
) -> Browser:
|
||||
|
|
@ -50,29 +53,35 @@ async def AsyncNewBrowser(
|
|||
|
||||
Parameters:
|
||||
playwright (Playwright):
|
||||
The playwright instance to use.
|
||||
Playwright instance to use.
|
||||
config (Optional[Dict[str, Any]]):
|
||||
The configuration to use.
|
||||
Configuration to use.
|
||||
addons (Optional[List[str]]):
|
||||
The addons to use.
|
||||
Addons to use.
|
||||
fingerprint (Optional[Fingerprint]):
|
||||
The fingerprint to use.
|
||||
BrowserForge fingerprint to use.
|
||||
exclude_addons (Optional[List[DefaultAddons]]):
|
||||
The default addons to exclude, passed as a list of camoufox.DefaultAddons enums.
|
||||
Default addons to exclude. Passed as a list of camoufox.DefaultAddons enums.
|
||||
screen (Optional[browserforge.fingerprints.Screen]):
|
||||
The screen constraints to use.
|
||||
BrowserForge screen constraints to use.
|
||||
os (Optional[ListOrString]):
|
||||
The operating system to use for the fingerprint. Either a string or a list of strings.
|
||||
Operating system to use for the fingerprint. Either a string or a list of strings.
|
||||
user_agent (Optional[ListOrString]):
|
||||
The user agent to use for the fingerprint. Either a string or a list of strings.
|
||||
User agent to use for the fingerprint. Either a string or a list of strings.
|
||||
fonts (Optional[List[str]]):
|
||||
The fonts to load into Camoufox, in addition to the default fonts.
|
||||
Fonts to load into Camoufox, in addition to the default fonts.
|
||||
args (Optional[List[str]]):
|
||||
The arguments to pass to the browser.
|
||||
executable_path (Optional[str]):
|
||||
The path to the Camoufox browser executable.
|
||||
Arguments to pass to the browser.
|
||||
block_images (Optional[bool]):
|
||||
Whether to block all images.
|
||||
block_webrtc (Optional[bool]):
|
||||
Whether to block WebRTC entirely.
|
||||
firefox_user_prefs (Optional[Dict[str, Any]]):
|
||||
Firefox user preferences to set.
|
||||
env (Optional[Dict[str, Union[str, float, bool]]]):
|
||||
The environment variables to set.
|
||||
Environment variables to set.
|
||||
executable_path (Optional[str]):
|
||||
Custom Camoufox browser executable path.
|
||||
**launch_options (Dict[str, Any]):
|
||||
Additional Firefox launch options.
|
||||
"""
|
||||
|
|
@ -88,5 +97,8 @@ async def AsyncNewBrowser(
|
|||
args=args,
|
||||
executable_path=executable_path,
|
||||
env=env,
|
||||
block_images=block_images,
|
||||
block_webrtc=block_webrtc,
|
||||
firefox_user_prefs=firefox_user_prefs,
|
||||
)
|
||||
return await playwright.firefox.launch(**opt, **launch_options)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ def NewBrowser(
|
|||
fonts: Optional[List[str]] = None,
|
||||
args: Optional[List[str]] = None,
|
||||
executable_path: Optional[str] = None,
|
||||
block_images: Optional[bool] = None,
|
||||
block_webrtc: Optional[bool] = None,
|
||||
firefox_user_prefs: Optional[Dict[str, Any]] = None,
|
||||
env: Optional[Dict[str, Union[str, float, bool]]] = None,
|
||||
**launch_options: Dict[str, Any]
|
||||
) -> Browser:
|
||||
|
|
@ -50,29 +53,35 @@ def NewBrowser(
|
|||
|
||||
Parameters:
|
||||
playwright (Playwright):
|
||||
The playwright instance to use.
|
||||
Playwright instance to use.
|
||||
config (Optional[Dict[str, Any]]):
|
||||
The configuration to use.
|
||||
Configuration to use.
|
||||
addons (Optional[List[str]]):
|
||||
The addons to use.
|
||||
Addons to use.
|
||||
fingerprint (Optional[Fingerprint]):
|
||||
The fingerprint to use.
|
||||
BrowserForge fingerprint to use.
|
||||
exclude_addons (Optional[List[DefaultAddons]]):
|
||||
The default addons to exclude, passed as a list of camoufox.DefaultAddons enums.
|
||||
Default addons to exclude. Passed as a list of camoufox.DefaultAddons enums.
|
||||
screen (Optional[browserforge.fingerprints.Screen]):
|
||||
The screen constraints to use.
|
||||
BrowserForge screen constraints to use.
|
||||
os (Optional[ListOrString]):
|
||||
The operating system to use for the fingerprint. Either a string or a list of strings.
|
||||
Operating system to use for the fingerprint. Either a string or a list of strings.
|
||||
user_agent (Optional[ListOrString]):
|
||||
The user agent to use for the fingerprint. Either a string or a list of strings.
|
||||
User agent to use for the fingerprint. Either a string or a list of strings.
|
||||
fonts (Optional[List[str]]):
|
||||
The fonts to load into Camoufox, in addition to the default fonts.
|
||||
Fonts to load into Camoufox, in addition to the default fonts.
|
||||
args (Optional[List[str]]):
|
||||
The arguments to pass to the browser.
|
||||
executable_path (Optional[str]):
|
||||
The path to the Camoufox browser executable.
|
||||
Arguments to pass to the browser.
|
||||
block_images (Optional[bool]):
|
||||
Whether to block all images.
|
||||
block_webrtc (Optional[bool]):
|
||||
Whether to block WebRTC entirely.
|
||||
firefox_user_prefs (Optional[Dict[str, Any]]):
|
||||
Firefox user preferences to set.
|
||||
env (Optional[Dict[str, Union[str, float, bool]]]):
|
||||
The environment variables to set.
|
||||
Environment variables to set.
|
||||
executable_path (Optional[str]):
|
||||
Custom Camoufox browser executable path.
|
||||
**launch_options (Dict[str, Any]):
|
||||
Additional Firefox launch options.
|
||||
"""
|
||||
|
|
@ -88,5 +97,8 @@ def NewBrowser(
|
|||
args=args,
|
||||
executable_path=executable_path,
|
||||
env=env,
|
||||
block_images=block_images,
|
||||
block_webrtc=block_webrtc,
|
||||
firefox_user_prefs=firefox_user_prefs,
|
||||
)
|
||||
return playwright.firefox.launch(**opt, **launch_options)
|
||||
|
|
|
|||
|
|
@ -164,6 +164,9 @@ def get_launch_options(
|
|||
args: Optional[List[str]] = None,
|
||||
executable_path: Optional[str] = None,
|
||||
env: Optional[Dict[str, Union[str, float, bool]]] = None,
|
||||
block_images: Optional[bool] = None,
|
||||
block_webrtc: Optional[bool] = None,
|
||||
firefox_user_prefs: Optional[Dict[str, Any]] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Builds the launch options for the Camoufox browser.
|
||||
|
|
@ -212,6 +215,15 @@ def get_launch_options(
|
|||
target_os = get_target_os(config)
|
||||
update_fonts(config, target_os)
|
||||
|
||||
# Set Firefox user preferences
|
||||
if firefox_user_prefs is None:
|
||||
firefox_user_prefs = {}
|
||||
|
||||
if block_images:
|
||||
firefox_user_prefs['permissions.default.image'] = 2
|
||||
if block_webrtc:
|
||||
firefox_user_prefs['media.peerconnection.enabled'] = False
|
||||
|
||||
# Launch
|
||||
threaded_try_load_addons(get_debug_port(args), addons)
|
||||
env_vars = {
|
||||
|
|
@ -222,4 +234,5 @@ def get_launch_options(
|
|||
"executable_path": executable_path or get_path(LAUNCH_FILE[OS_NAME]),
|
||||
"args": args,
|
||||
"env": env_vars,
|
||||
"firefox_user_prefs": firefox_user_prefs,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|||
|
||||
[tool.poetry]
|
||||
name = "camoufox"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
description = "Wrapper around Playwright to help launch Camoufox"
|
||||
authors = ["daijro <daijro.dev@gmail.com>"]
|
||||
license = "MIT"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue