angular / angular/components

feat(Platform): allow DI override of userAgent

Open
#33,751 3 comments 0 reactions 0 assignees View on GitHub
area: cdk/platform feature gemini-triaged needs triage
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Feature Description

Right now it is hardcoded as global `navigator.userAgent`:
https://github.com/angular/components/blob/main/src/cdk/platform/platform.ts

However in SSR there's a way to get userAgent from the request and accessing global entities is bad practice. Would be great if there was a token for userAgent [like we do here](https://github.com/taiga-family/ng-web-apis/blob/main/libs/common/src/tokens/user-agent.ts), or maybe at least `inject(DOCUMENT).defaultView?.navigator?.userAgent` way of accessing it, rather than just global `navigator.userAgent`

### Use Case

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in src/cdk/platform/platform.ts, where the global navigator.userAgent access is defined, and inspect the surrounding platform injection setup. Compare the requested injectable user-agent source with the existing DOCUMENT access and verify the result in SSR while preserving browser behavior; done means callers can override the user agent through DI.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.