Skip to content

refactor: replace ua-parser-js with lightweight browser detection (-26 KB)#4972

Open
PascalThuet wants to merge 3 commits intoDash-Industry-Forum:developmentfrom
PascalThuet:optim/replace-ua-parser-js
Open

refactor: replace ua-parser-js with lightweight browser detection (-26 KB)#4972
PascalThuet wants to merge 3 commits intoDash-Industry-Forum:developmentfrom
PascalThuet:optim/replace-ua-parser-js

Conversation

@PascalThuet
Copy link
Contributor

Summary

  • Remove ua-parser-js dependency (~26 KB minified)
  • Replace with simple regex-based browser detection in Utils.parseUserAgent()
  • -25,855 bytes on dash.all.min.js (-2.6%)

What changed

src/core/Utils.js: removed import {UAParser} from 'ua-parser-js' and replaced the parseUserAgent() method body with two regex tests for the only browser names dash.js checks: safari and edge. Return type { browser: { name: string } } is unchanged.

package.json: removed ua-parser-js from dependencies.

package-lock.json: regenerated.

The two call sites are unchanged:

  • CatchupController.js:125ua.browser.name === 'safari'
  • ProtectionController.js:1491ua.browser.name === 'edge'

Bundle size

Measured on development branch (v5.2.0), modern prod build:

Before After Diff
dash.all.min.js 983,658 B 957,803 B -25,855 B (-2.6%)
dash.all.debug.js 3,503,300 B 3,431,577 B -71,723 B (-2.0%)

Test plan

  • All 3,332 unit tests pass without modification
  • Manual: live playback (exercises CatchupController Safari path)
  • Manual: DRM playback with PlayReady (exercises ProtectionController Edge path)

Fixes #4971

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
Copilot AI review requested due to automatic review settings March 1, 2026 16:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-js from package.json dependencies.
  • Regenerated package-lock.json to 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)
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.

Reduce bundle size: replace ua-parser-js dependency (-26 KB / -2.6%)

2 participants