Skip to content

Refactor browser info collection to use User-Agent Client Hints API#21

Open
morvader wants to merge 3 commits intomasterfrom
claude/enhance-browser-detection-mnSst
Open

Refactor browser info collection to use User-Agent Client Hints API#21
morvader wants to merge 3 commits intomasterfrom
claude/enhance-browser-detection-mnSst

Conversation

@morvader
Copy link
Owner

Summary

This PR modernizes the browser and system information collection by migrating from deprecated APIs to the User-Agent Client Hints API (navigator.userAgentData). The function is now async to support the asynchronous getHighEntropyValues() method, and collects significantly more detailed system information.

Key Changes

  • Async function: getSystemInfo() is now async to support the User-Agent Client Hints API's asynchronous high entropy values retrieval
  • Enhanced data collection: Now captures:
    • Browser brand and full version (from userAgentData.fullVersionList)
    • Device model information
    • OS platform and version (from userAgentData.platformVersion)
    • Screen resolution
    • User language preference
    • Timezone information
  • Removed deprecated data: Eliminated hardcoded "Chrome" browser name, Flash version reporting, and reliance on chrome.runtime.getManifest()
  • Graceful fallback: Includes try-catch to handle cases where high entropy values are unavailable, falling back to basic userAgentData.brands
  • Smart brand filtering: Filters out placeholder brands like "Not A;Brand" and "Chromium" to identify the actual browser brand
  • Updated test suite: Comprehensive tests for all new properties with proper async/await handling
  • Updated mock setup: Enhanced Jest setup with proper userAgentData, screen, and Intl mocks
  • UI improvements: Updated report display to show browser brand, model, version, OS version, resolution, language, and timezone
  • Backward compatibility: Session and export functions updated to handle both old browser and new brand properties

Implementation Details

  • The function attempts to retrieve high entropy values (full version list, platform version, model) but gracefully degrades if the browser doesn't support them
  • Brand detection prioritizes the first non-placeholder brand from the fullVersionList or brands array
  • All new properties have fallback values to ensure the function always returns a complete object
  • The UI layer includes defensive checks for missing properties to maintain compatibility with older data formats

https://claude.ai/code/session_013y1QH2gkj8wg427JpzjdJe

claude added 3 commits March 10, 2026 05:01
- Replace hardcoded browser info with navigator.userAgentData API to get
  real brand, full version (e.g. 122.0.6261.112), OS platform and version
- Remove deprecated navigator.platform and raw userAgent dump
- Add screen resolution, browser language, timezone and cookies to session data
- Make getSystemInfo() async to support high-entropy API values
- Update background.js to await getSystemInfo() and use brand for filenames
- Update HTML report to display all 8 new fields with backwards compatibility
  for sessions stored with the old format (browser/browserVersion fields)
- Update jest mocks and browserInfo.test.js to match new async API

https://claude.ai/code/session_013y1QH2gkj8wg427JpzjdJe
The background.js service worker does not have access to the window
screen object. Accessing screen.width threw a ReferenceError which
silently prevented startSession() from completing and blocked all
annotation saves.

Added typeof screen !== 'undefined' guard so screenResolution falls
back to 'N/A' when running in service worker context.

https://claude.ai/code/session_013y1QH2gkj8wg427JpzjdJe
- Fix getFullSession handler to pass BrowserInfo directly instead of
  mapping to old format (this was causing all new fields to be lost)
- Fix brand detection: match real browser by comparing major version
  against Chromium's version, avoiding randomized fake brand names
- Remove screenResolution, language, timezone and cookies from
  getSystemInfo() — these cannot be obtained reliably from service worker
- Update reportUI.js to display only: start date, browser, version, OS
- Remove unnecessary screen/Intl mocks from jest.setup.js

https://claude.ai/code/session_013y1QH2gkj8wg427JpzjdJe
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.

2 participants