stealth

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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

View Source
var DefaultLanguages = []string{"en-US", "en"}
View Source
var EvasionsJS string

EvasionsJS holds the embedded JavaScript used for browser fingerprint evasion.

Functions

func Apply

func Apply(persona schemas.Persona, logger *zap.Logger) chromedp.Tasks

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:

  1. Marshalling the `Persona` into a JSON object.
  2. Creating a JavaScript payload that injects the persona and the main evasion script.
  3. Adding a CDP action to inject this script on all new documents.
  4. 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

func ApplyStealthEvasions(ctx context.Context, persona schemas.Persona, logger *zap.Logger) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL