Skip to content

fix: derive chrome fingerprint version from installed datapack at runtime - #398

Open
albatrossflyon-coder wants to merge 1 commit into
D4Vinci:devfrom
albatrossflyon-coder:dev
Open

fix: derive chrome fingerprint version from installed datapack at runtime#398
albatrossflyon-coder wants to merge 1 commit into
D4Vinci:devfrom
albatrossflyon-coder:dev

Conversation

@albatrossflyon-coder

Copy link
Copy Markdown

Fixes #396

Root cause

The module-level chromium_version = 149 / chrome_version = 149 constants in scrapling/engines/toolbelt/fingerprints.py were hardcoded above the newest Chrome version the installed apify-fingerprint-datapoints release actually ships fingerprint data for (max 143 on apify-fingerprint-datapoints==0.14.0). Since __default_useragent__ is computed at module import time, browserforge's HeaderGenerator raises ValueError: No headers based on this input can be generated as soon as Scrapling is imported.

This is not platform-specific. The issue was originally reported on Linux and confirmed on macOS in the comments, but the same mismatch reproduces identically on Windows — I verified this live before writing the fix.

Fix

Instead of hardcoding a version number that will drift ahead of the installed datapack on every future Scrapling/browserforge release (as pointed out in the issue thread), derive the newest supported Chrome version directly from the installed datapack's own browser-helper-file.json at import time via a small cached helper, _max_supported_version(). This is the same data browserforge's own HeaderGenerator._load_unique_browsers() already reads, so it's guaranteed to stay in sync with whatever datapack version is actually installed — no more hardcoded floor to bump on every release.

Testing

  • Reproduced the bug live (ValueError on generate_headers(browser_mode="chrome")) before the fix, confirmed it's resolved after
  • Added two regression tests in tests/fetchers/test_utils.py: one asserting the version constants match the datapack's actual max, one asserting header generation in chrome mode no longer raises
  • Full existing test suite in tests/fetchers/test_utils.py passes (5/5, including the 2 new tests)
  • ruff check / ruff format --check: clean
  • bandit: no issues
  • mypy / pyright: no issues
  • vermin -t=3.10-: confirms 3.10, matching requires-python
  • Static analysis (semgrep, security-audit + secrets rulesets): 0 findings

Note

Added a defensive check so _max_supported_version() raises a clear error instead of an opaque max() arg is an empty sequence if it's ever called with a browser name absent from the datapack (not reachable today since it's only called with "chrome", which is always present, but worth guarding since it's a general-purpose helper).

…time

The hardcoded `chromium_version = 149` / `chrome_version = 149` constants
were newer than what the installed `apify-fingerprint-datapoints` release
actually ships fingerprint data for (max 143 on 0.14.0). Playwright doesn't
expose the real installed browser version without launching it, so instead
of hardcoding a number that drifts ahead of the datapack on every release,
derive the newest supported version directly from the datapack's own
browser-helper-file.json at import time.

Fixes D4Vinci#396. Reproduced and verified live on Windows (issue previously
reported as Linux/macOS-only) - generate_headers(browser_mode="chrome")
raised ValueError before this change, generates real headers after it.
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.

1 participant