fix: fix the problem that userAgentData.brands might be undefined#2058
Open
Rossonero wants to merge 1 commit into
Open
fix: fix the problem that userAgentData.brands might be undefined#2058Rossonero wants to merge 1 commit into
Rossonero wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a runtime error where navigator.userAgentData.brands could be undefined in certain browsers or privacy-restricted environments, causing the isChromiumBased() function to fail.
Changes:
- Added explicit check for
navigator.userAgentData.brandsarray existence before attempting to access it - Prevents TypeError when
brandsproperty is undefined due to browser compatibility or privacy settings
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
SlicedSilver
approved these changes
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of PR: bugfix
PR checklist:
Fixes #2046
Overview of change:
This PR fixes the issue that
navigator.userAgentData.brandsis sometimesundefinedin some environments. The root causes are browser compatibility (e.g., Firefox, Safari do not supportnavigator.userAgentDataAPI) and privacy policy restrictions (e.g., strict privacy mode in Chromium-based browsers disables the API).The fix implements a compatible solution:
First check if
navigator.userAgentDataandnavigator.userAgentData.brandsexist; if they do, use the standard API as before.If not, degrade to parse the traditional
navigator.userAgentstring to extract browser brand and version information, ensuring consistent return format and avoiding code errors.Filter the placeholder brand
Not/A)Brandinbrandsarray (added by browsers for anti-fingerprinting) to ensure the returned data is valid and usable.This change is backward-compatible, does not affect existing functionality in supported browsers, and effectively resolves the
undefinederror in unsupported environments or privacy-restricted scenarios.Is there anything you'd like reviewers to focus on?
Whether the compatible logic of
navigator.userAgentDataandnavigator.userAgentis complete, and if there are any edge cases (e.g., special browser userAgent strings) not covered.Whether the return format of the browser information is consistent with the original design, to avoid affecting subsequent business logic that depends on this data.
Whether the filtering logic of
Not/A)Brandis reasonable and does not filter out valid brand information.