fix: derive Chromium User-Agent from actual browser version
The hardcoded DefaultChromiumUserAgent said Chrome/131 while the installed Chromium was v136. Chromium's sec-ch-ua header is generated from the real engine version, so sites comparing User-Agent against sec-ch-ua detected the mismatch as bot traffic and returned 403. Now the User-Agent is built after browser launch using browser.Version(), keeping the Chrome/N token in sync with sec-ch-ua's Chromium;v="N". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+18
@@ -3,6 +3,7 @@ package extractor
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// stealthChromiumArgs are launch arguments that reduce automation detection for Chromium-based browsers.
|
||||
@@ -269,3 +270,20 @@ func buildFirefoxStealthScripts(p firefoxHWProfile) []string {
|
||||
})`,
|
||||
}
|
||||
}
|
||||
|
||||
// chromiumUserAgent builds a Chromium User-Agent string from the actual
|
||||
// browser version. This keeps the UA in sync with the sec-ch-ua header
|
||||
// that Chromium sends automatically, avoiding a version mismatch that
|
||||
// anti-bot systems use to detect automation.
|
||||
func chromiumUserAgent(version string) string {
|
||||
// version is typically "136.0.7103.25"; we need the major for the
|
||||
// Chrome/MAJ.0.0.0 token and the full version for the template.
|
||||
major := version
|
||||
if i := strings.IndexByte(version, '.'); i > 0 {
|
||||
major = version[:i]
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s.0.0.0 Safari/537.36",
|
||||
major,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user