refactor: replace ua-parser-js with lightweight browser detection (-26 KB)#4972
Open
PascalThuet wants to merge 3 commits intoDash-Industry-Forum:developmentfrom
Open
refactor: replace ua-parser-js with lightweight browser detection (-26 KB)#4972PascalThuet wants to merge 3 commits intoDash-Industry-Forum:developmentfrom
PascalThuet wants to merge 3 commits intoDash-Industry-Forum:developmentfrom
Conversation
Remove the ua-parser-js dependency (~26 KB minified) and replace it with simple regex-based detection in Utils.parseUserAgent(). dash.js only uses this to check for Safari and Edge browser names in two call sites. Fixes Dash-Industry-Forum#4971
There was a problem hiding this comment.
Pull request overview
Refactors user-agent parsing to drop the ua-parser-js dependency and replace it with lightweight, targeted browser detection to reduce the built bundle size.
Changes:
- Replaced
Utils.parseUserAgent()implementation with regex-based detection for Edge and Safari. - Removed
ua-parser-jsfrompackage.jsondependencies. - Regenerated
package-lock.jsonto reflect dependency removal.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/core/Utils.js | Removes UAParser usage and adds minimal { browser: { name } } detection logic. |
| package.json | Drops ua-parser-js dependency to reduce bundle size. |
| package-lock.json | Updates lockfile to remove ua-parser-js and related packages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix ua parameter being ignored when provided as string - Exclude iOS browsers (CriOS, FxiOS) from Safari detection - Add unit tests for parseUserAgent - Move ua-parser-js to devDependencies for functional tests
Add 7 additional tests for browser detection edge cases: - Safari on iOS (real Safari, not CriOS/FxiOS) - Safari on iPadOS (desktop UA since iPadOS 13) - Edge on Android (EdgA token) - Opera exclusion (OPR token) - Firefox desktop (no Safari/Edge token) - Empty string input - Explicit null parameter (navigator fallback)
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.
Summary
ua-parser-jsdependency (~26 KB minified)Utils.parseUserAgent()dash.all.min.js(-2.6%)What changed
src/core/Utils.js: removedimport {UAParser} from 'ua-parser-js'and replaced theparseUserAgent()method body with two regex tests for the only browser names dash.js checks:safariandedge. Return type{ browser: { name: string } }is unchanged.package.json: removedua-parser-jsfrom dependencies.package-lock.json: regenerated.The two call sites are unchanged:
CatchupController.js:125—ua.browser.name === 'safari'ProtectionController.js:1491—ua.browser.name === 'edge'Bundle size
Measured on
developmentbranch (v5.2.0), modern prod build:dash.all.min.jsdash.all.debug.jsTest plan
Fixes #4971