Misc

Stealth Techniques - Controlling What the Browser Reveals

User Agent

WithUseUserAgent(string) sets the User-Agent header for every request in the session. Use it to appear as a different browser, OS, or device. The value is applied before the first GoTo and persists for the entire session. Pass an empty string to restore the browser default.

string mobileUA =

"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 " +

"like Mac OS X) AppleWebKit/605.1.15 " +

"(KHTML, like Gecko) Version/17.0 Mobile";


GPAL.Browser

.WithUseUserAgent(mobileUA)

.GoTo("https://example.com")

.WithSelector(mobileOnlySel)

.GetGrid(out IGPALGrid<string> results)

.Close();

NOTE

GPAL applies three Chrome/Edge flags unconditionally on every session: --disable-blink-features=AutomationControlled (removes navigator.webdriver), excludeSwitches:enable-automation (hides the controlled-by-automation infobar), and useAutomationExtension:false. No configuration needed -- they are always active.

Referrer Headers

WithUseReferrer(string) attaches the Referer header to every GoTo and Get call for the life of the session -- use it when you want to simulate traffic arriving from a specific page. ClearReferrer() removes whichever override is active.

// Set any referrer for the whole session:

GPAL.Browser

.WithUseReferrer("https://news.ycombinator.com")

.GoTo("https://target-site.com")

.WithSelector(sel)

.GetGrid(out IGPALGrid<string> results)

.Close();


// Remove the active referrer override:

GPAL.Browser.ClearReferrer();

NOTE

Use StealthType.GoogleReferrer with WithUseStealth() to hard-code the referrer to https://www.google.com/ at launch time -- making the session look like it arrived from a search result click. This is set once at the first GoTo as part of the launch-time stealth block, not mid-chain.

WithUseStealth - Launch-Time Protections

WithUseStealth takes a bitmask of StealthType flags applied once at the first GoTo. CDP injects a script before any page code runs to hide the remote debugging port from in-page detection. ToStringOverride masks automation-specific toString values that fingerprinting scripts check. DarkMode launches the browser in dark mode. GoogleReferrer sets the Referer header to google.com at the first navigation. PatchDriver patches the active driver binary -- chromedriver.exe for Chrome, msedgedriver.exe for Edge -- before the session starts. It removes the window.cdc_* variables that Selenium injects (a primary bot-detection signal), mutates a set of known fingerprintable strings such as WebDriver, W3C, and Execute-Script by shifting the first character, and replaces the driver startup console.log with a GPAL version stamp that also serves as an idempotency check. All replacements preserve the exact original byte length since this is an in-place binary patch. All flags are launch-time only and cannot be changed after the browser starts.

// Flags can be combined with |:

GPAL.Browser

.WithUseStealth(

StealthType.CDP |

StealthType.ToStringOverride |

StealthType.PatchDriver)

.GoTo(url)

...


// Or apply every flag at once:

GPAL.Browser

.WithUseStealth(StealthType.All)

.GoTo(url)

...

NOTE

OttoMagic drives the browser entirely through JavaScript executed in content scripts and background scripts. Chrome messaging is used for communication between those layers -- the actual automation work is JavaScript calling the underlying browser APIs directly. This means there is no WebDriver protocol, no CDP connection, and no driver binary for detection systems to fingerprint. When evasion is the primary requirement, WithUseAutomationEngine(AutomationEngine.OttoMagic) is the strongest starting point.

💬 Ask GPAL