Documentation
¶
Overview ¶
internal/browser/stealth/stealth.go package stealth provides functionality to apply various browser fingerprinting evasions. It works by injecting a sophisticated JavaScript payload (`evasions.js`) into every new document created in a browser session. This script runs before any page scripts, allowing it to override and patch browser APIs that are commonly used for fingerprinting (e.g., `navigator.plugins`, `WebGLRenderingContext`).
In addition to the JavaScript evasions, this package also uses the Chrome DevTools Protocol (CDP) to apply "defense-in-depth" overrides for fundamental browser properties like the User-Agent, platform, viewport dimensions, and timezone. These configurations are derived from a `schemas.Persona` object, ensuring that the browser's fingerprint is consistent across both the CDP and JavaScript layers.
Index ¶
Constants ¶
const ( DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" DefaultPlatform = "Win32" DefaultDPR = 1.0 MaxDPR = 5.0 // Maximum reasonable DPR to prevent browser instability. )
Constants for default values and limits
Variables ¶
var DefaultLanguages = []string{"en-US", "en"}
var EvasionsJS string
EvasionsJS holds the embedded JavaScript used for browser fingerprint evasion.
Functions ¶
func Apply ¶
Apply constructs a `chromedp.Tasks` list that, when executed, will apply all the necessary stealth and persona emulation configurations to a browser session. It combines JavaScript injection with direct CDP command overrides.
The process includes:
- Marshalling the `Persona` into a JSON object.
- Creating a JavaScript payload that injects the persona and the main evasion script.
- Adding a CDP action to inject this script on all new documents.
- Adding CDP actions to override the User-Agent, platform, languages, timezone, locale, and device metrics.
Note: This function returns a `chromedp.Tasks` object, which is a slice of `chromedp.Action`. It must be executed using `chromedp.Run`, as it contains low-level CDP commands that are not compatible with `chromedp.Tasks{...}.Do()`.
func ApplyStealthEvasions ¶
ApplyStealthEvasions is a high-level convenience function that constructs the stealth configuration tasks via `Apply` and immediately executes them on the provided context using `chromedp.Run`. This provides a simple, one-shot way to apply all evasions to an active browser context.
Types ¶
This section is empty.