#
Usage
Camoufox is fully compatible with your existing Playwright code. You only have to change your browser initialization:
from camoufox.sync_api import Camoufox
with Camoufox() as browser:
page = browser.new_page()
page.goto("https://example.com")
from camoufox.async_api import AsyncCamoufox
async with AsyncCamoufox() as browser:
page = await browser.new_page()
await page.goto("https://example.com")
#
Parameters List
All Playwright Firefox launch options are accepted, along with the following:
Camoufox will generate device information for you based on the following parameters.
Type: Optional[ListOrString]
Operating system to use for the fingerprint generation.
Can be "windows"
, "macos"
, "linux"
, or a list to randomly choose from. By default, Camoufox will randomly choose from a list of all three.
# Use a specific OS
with Camoufox(os="windows") as browser:
...
# Randomly choose from a list of OS
with Camoufox(os=["windows", "macos", "linux"]) as browser:
...
Type: Optional[List[str]]
Fonts to load into Camoufox, in addition to the default fonts for the target os
. Takes a list of font family names that are installed on the system.
custom_fonts = ["Arial", "Helvetica", "Times New Roman"]
with Camoufox(fonts=custom_fonts) as browser:
...
Type: Optional[Screen]
Constrains the screen dimensions of the generated fingerprint.
Takes a browserforge.fingerprints.Screen
instance.
While this sets the screen dimensions, it has very light impact on the size of the window. Sometimes the window will be larger, sometimes smaller.
from browserforge.fingerprints import Screen
constrains = Screen(max_width=1920, max_height=1080)
with Camoufox(screen=constrains) as browser:
...
Type: Optional[Tuple[str, str]]
Use a specific WebGL vendor/renderer pair. Passed as a tuple of (vendor, renderer). The vendor & renderer combination must be supported for the target os
or this will cause leaks.
Check here for a list of Camoufox's supported vendor & renderer combinations.
with Camoufox(
webgl_config=("Apple", "Apple M1, or similar"),
os="macos",
) as browser:
...
Type: Optional[Dict[str, Any]]
If needed, individual Camoufox config properties can be overridden by passing them as a dictionary to the config
parameter. This can be used to enable features that have not yet been implemented into the Python library.
This is an advanced feature and should be used with caution. The Camoufox Python library is designed to populate these properties for you.
Extra feature configuration and quality of life options.
Type: Optional[Union[bool, float]]
Humanize the cursor movement.
Takes either True
, or the MAX duration in seconds of the cursor movement.
The cursor typically takes up to 1.5 seconds to move across the window.
# Enable humanization with default settings
with Camoufox(humanize=True) as browser:
...
# Set a custom max duration for cursor movement
with Camoufox(humanize=2.0) as browser:
...
Type: Optional[Union[bool, Literal['virtual']]]
Whether to run the browser in headless mode. Defaults to False. If you are running linux, passing 'virtual' will use Xvfb.
# Run in headless mode
with Camoufox(headless=True) as browser:
...
# Run in headless mode on linux
with Camoufox(headless="virtual") as browser:
...
Type: Optional[List[str]]
List of Firefox addons to use. Must be paths to extracted addons.
To load an .xpi
file, rename it to a .zip
file, extract it, and pass the extracted folder.
addons = ["/path/to/addon1", "/path/to/addon2"]
with Camoufox(addons=addons) as browser:
...
Type: Optional[List[DefaultAddons]]
Exclude the default addons. Passed as a list of camoufox.DefaultAddons
enums.
Type: Optional[Tuple[int, int]]
Set the window size in (width, height) pixels. This will also set the window.screenX
and window.screenY
properties to position the window at the center of the generated screen.
Camoufox will automatically generate a window size for you. Using a fixed window size can lead to fingerprinting. Do not set the window size to a fixed value unless for debugging purposes.
with Camoufox(window=(1282, 955)) as browser:
...
Type: Optional[bool]
Whether to cache previous pages, requests, etc. Disabled by default as it uses more memory.
Keeping this disabled will not allow you to use the page.go_back()
or page.go_forward()
methods.
with Camoufox(enable_cache=True) as browser:
...
Type: Optional[bool]
Whether to create a persistent context. Requires user_data_dir
.
with Camoufox(
persistent_context=True,
user_data_dir='/path/to/profile/dir',
) as context:
...
Prevent proxy detection by matching your geolocation & locale with your target IP. This will populate the Geolocation & Intl properties for you.
Type: Optional[Union[str, bool]]
Calculates longitude, latitude, timezone, country, & locale based on the IP address.
Pass the target IP address to use, or True
to find the IP address automatically.
# Use a specific IP address
with Camoufox(geoip="203.0.113.0", proxy=...) as browser:
...
# Automatically find the IP address
with Camoufox(geoip=True, proxy=...) as browser:
...
Type: Optional[Union[str, List[str]]]
Locale(s) to use in Camoufox. Can be a list of strings, or a single string separated by a comma. The first locale in the list will be used for the Intl API.
# Use a single locale
with Camoufox(locale="en-US") as browser:
...
# Generate a language based on the distribution of speakers the US
with Camoufox(locale="US") as browser:
...
# Use multiple accepted locales
with Camoufox(locale=["en-US", "fr-FR", "de-DE"]) as browser:
...
with Camoufox(locale="en-US,fr-FR,de-DE") as browser:
...
Shortcuts for common Firefox preferences and security toggles.
Type: Optional[bool]
Blocks all requests to images. This can help save your proxy usage.
with Camoufox(block_images=True) as browser:
...
Type: Optional[bool]
Blocks WebRTC entirely.
with Camoufox(block_webrtc=True) as browser:
...
Type: Optional[bool]
Whether to block WebGL. To prevent leaks, only use this for special cases.
with Camoufox(block_webgl=True) as browser:
...
Camoufox will warn you if your passed configuration might cause leaks.
#
More Usage Docs