Skip to content

fix(user-agent): honour the requested browser_type - #2567

Open
HhH666-ux wants to merge 1 commit into
unclecode:mainfrom
HhH666-ux:fix/user-agent-browser-type
Open

HhH666-ux wants to merge 1 commit into
unclecode:mainfrom
HhH666-ux:fix/user-agent-browser-type

Conversation

@HhH666-ux

@HhH666-ux HhH666-ux commented Nov 16, 2026 •

Copy link
Copy Markdown

Problem

UserAgentGenerator.generate(browser_type=...) builds the browser stack with get_browser_stack(num_browsers), which picks each browser at random. generate(browser_type='firefox') can therefore return a Chrome or Edge user agent, and the legacy token branch already keys off the requested type, so the result is internally inconsistent.

Fix

When browser_type is set, choose one version from that browser's list (the same lists get_browser_stack() uses) instead of a random stack. Without a requested type, the previous random behaviour is unchanged.

Tests

tests/test_user_agent_browser_type.py stubs get_browser_stack() to return a Chrome stack and asserts that firefox and edge requests still produce Firefox/Edge user agents without Chrome/Edg leakage. python -m pytest tests/test_user_agent_browser_type.py -q: 2 passed. python -m py_compile clean; no browser or network needed.

Fixes #2566.

generate() accepted browser_type but built the browser stack with
random.choice over every browser, so a firefox request could return a Chrome
or Edge user agent while the legacy token branch already assumed the requested
browser.

Pick the version from the requested browser's list and keep the random stack
only when no type is requested.

Fixes unclecode#2566.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: UserAgentGenerator.generate ignores browser_type and returns a random browser stack

1 participant