Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user agent parsing #1607

Merged
merged 20 commits into from
Oct 21, 2024
Merged

feat: user agent parsing #1607

merged 20 commits into from
Oct 21, 2024

Conversation

taddes
Copy link
Contributor

@taddes taddes commented Oct 7, 2024

Description

Addition of User Agent parsing, consisting of:
Platform (Firefox Desktop, Firefox iOS, Fenix, Other)
Device family (Desktop, Mobile, Tablet, Other)
OS family (Mac, Windows, Linux, iOS, Android, other)

Note: User agent emission from iOS clients is non-standard. Two observed variants occur:
Firefox-iOS-FxA/24 or Firefox-iOS-Sync/115.0b32242 (iPhone; iPhone OS 17.7) (Firefox)
See the shared spreadsheet in SYNC-4413 for details.

As a result of Woothee being unable to parse this non-standard user agent, custom logic was added to fill in the gaps to so that the association logic can work to fill out all the matching enum values.

Subsequent PR will pull this into metarequest and apply the parsing.

Testing

Added unit tests within user_agent to verify new user_agent strings.

Issue(s)

Closes SYNC-4414.

@taddes taddes self-assigned this Oct 7, 2024
@taddes taddes force-pushed the feat/SYNC-4414_user_agent_parsing branch from 46a7112 to e4757ad Compare October 14, 2024 21:15
syncserver/src/server/user_agent.rs Outdated Show resolved Hide resolved
syncserver/src/server/user_agent.rs Outdated Show resolved Hide resolved
@taddes taddes marked this pull request as ready for review October 16, 2024 01:00
@taddes taddes requested review from jrconlin and pjenvey October 16, 2024 01:26
syncserver/src/server/user_agent.rs Outdated Show resolved Hide resolved
@taddes taddes force-pushed the feat/SYNC-4414_user_agent_parsing branch from 20a23d1 to c2ff37c Compare October 18, 2024 19:36
@taddes taddes requested a review from jrconlin October 18, 2024 20:56
Comment on lines +95 to +96
matches!(&self.device_family, DeviceFamily::Mobile)
&& matches!(&self.os_family, OsFamily::Android)
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a test for Platform::Other -- going by the spreadsheet, I'd expect "Mozilla/5.0 (Linux; Android 9; SM-A920F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4216.0 Mobile Safari/537.36" (Android Chrome I believe) to come back as it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made an implementation change, since the parsing logic was still getting the right OS and device family. I adjusted it to be that if the browser is not Firefox, return the Default implementation of DeviceInfo with Other as everything and FirefoxVersion of 0, making it easy to screen out, added test too

}
}

pub fn get_device_info(user_agent: &str) -> DeviceInfo {
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a note in the docs for this fn that it handles a mix regular user-agents and the sync specific ones. I guess the latter are mostly just the ios "Firefox-iOS-FxA/24" one. Desktop also has its sync specific "FxSync/<...>.desktop" thing but it doesn't end up requiring special handling

@taddes taddes requested a review from pjenvey October 21, 2024 19:21
@taddes taddes merged commit 7f2ef06 into master Oct 21, 2024
8 checks passed
@taddes taddes deleted the feat/SYNC-4414_user_agent_parsing branch October 21, 2024 21:09
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.

3 participants