Skip to Content
ReferencePythonopentele2.browser

opentele2.browser

Browser HTTP headers and fingerprints shaped as browserforge’s, drawn by the core from the opentele2-browser crate. HeaderGenerator and FingerprintGenerator take browserforge’s argument names and defaults; their generate methods also take seed (a str or int): the same seed and options always give the same output, on any platform. Without a seed every call draws from the operating system’s entropy. Options that cannot be met, or that are invalid, raise ValueError as in browserforge.

from opentele2.browser import Browser, FingerprintGenerator, HeaderGenerator, Screen

Constants

NameValue
SUPPORTED_BROWSERS("chrome", "firefox", "safari", "edge")
SUPPORTED_OPERATING_SYSTEMS("windows", "macos", "linux", "android", "ios")
SUPPORTED_DEVICES("desktop", "mobile")
SUPPORTED_HTTP_VERSIONS("1", "2")

HeaderGenerator

opentele2/browser.py
class HeaderGenerator: def __init__( self, browser: str | Sequence[str] | Iterable[str | Browser] = SUPPORTED_BROWSERS, os: str | Sequence[str] = SUPPORTED_OPERATING_SYSTEMS, device: str | Sequence[str] = SUPPORTED_DEVICES, locale: str | Sequence[str] = "en-US", http_version: Literal[1, 2, "1", "2"] = 2, strict: bool = False, ) -> None: ... def generate( self, *, browser: str | Sequence[str] | Iterable[str | Browser] | None = None, os: str | Sequence[str] | None = None, device: str | Sequence[str] | None = None, locale: str | Sequence[str] | None = None, http_version: Literal[1, 2, "1", "2"] | None = None, user_agent: str | Sequence[str] | None = None, strict: bool | None = None, request_dependent_headers: dict[str, str] | None = None, seed: str | int | None = None, ) -> dict[str, str]: ...
ArgumentDescription
browserBrowser names or Browser objects to draw from.
os, deviceOperating systems and device kinds to draw from.
localeAccept-Language locales, most preferred first, at most ten.
http_versionHTTP version of the headers and of every browser given by name; HTTP/1 falls back to HTTP/2 when no HTTP/1 sample fits.
strictFail instead of relaxing the options when nothing fits them.
user_agentWhen given, the generated User-Agent is one of these.
request_dependent_headersHeaders such as Referer or Cookie: one that matches a generated header replaces its value in place, any other is appended.
seedMakes the draw reproducible.

generate returns one set of headers, name to value in sending order; its arguments override the generator’s options for that call.

FingerprintGenerator

opentele2/browser.py
class FingerprintGenerator: def __init__( self, screen: Screen | None = None, strict: bool = False, mock_webrtc: bool = False, slim: bool = False, **header_kwargs: Any, ) -> None: ... def generate( self, *, screen: Screen | None = None, strict: bool | None = None, mock_webrtc: bool | None = None, slim: bool | None = None, seed: str | int | None = None, **header_kwargs: Any, ) -> Fingerprint: ...

header_kwargs are the HeaderGenerator arguments. screen bounds the screen of the fingerprint; with strict a screen no sample has fails instead of being dropped. mock_webrtc and slim are carried to the output for an injector.

Browser and Screen

opentele2/browser.py
@dataclass class Browser: name: str min_version: int | None = None max_version: int | None = None http_version: str | int = "2" @dataclass class Screen: min_width: int | None = None max_width: int | None = None min_height: int | None = None max_height: int | None = None def is_set(self) -> bool: ...

Browser bounds a browser’s major version, inclusive; Screen bounds the screen size, each side inclusive and None for open. A minimum above its maximum raises ValueError. Screen.is_set() tells whether any bound is set.

Fingerprint

opentele2/browser.py
@dataclass class Fingerprint: screen: ScreenFingerprint navigator: NavigatorFingerprint headers: dict[str, str] videoCodecs: dict[str, str] | None audioCodecs: dict[str, str] | None pluginsData: dict[str, Any] | None battery: dict[str, Any] | None videoCard: VideoCard | None multimediaDevices: dict[str, Any] | None fonts: list[str] | None mockWebRTC: bool | None slim: bool | None def dumps(self) -> str: ... @dataclass class VideoCard: renderer: str vendor: str

dumps() is the fingerprint as a JSON string, as browserforge’s dumps.

DataclassFields
ScreenFingerprintavailHeight, availWidth, availTop, availLeft, colorDepth, height, pixelDepth, width, devicePixelRatio, pageXOffset, pageYOffset, innerHeight, outerHeight, outerWidth, innerWidth, screenX, clientWidth, clientHeight, hasHDR
NavigatorFingerprintuserAgent, userAgentData, doNotTrack, appCodeName, appName, appVersion, oscpu, webdriver, language, languages, platform, deviceMemory, hardwareConcurrency, product, productSub, vendor, vendorSub, maxTouchPoints, extraProperties
VideoCardrenderer, vendor: the unmasked WebGL renderer and vendor
browser.py
from opentele2.browser import Browser, FingerprintGenerator, HeaderGenerator, Screen headers = HeaderGenerator(browser=[Browser("chrome", min_version=130)], os="windows").generate(seed=7) fingerprint = FingerprintGenerator(screen=Screen(max_width=1920)).generate(seed="profile-1") print(headers["User-Agent"]) print(fingerprint.headers["User-Agent"] == fingerprint.navigator.userAgent) # True print(fingerprint.screen.width, fingerprint.dumps()[:80])
Last updated on