Skip to content

[Bug] Incorrect User Agent Detection for Chrome on iOS #16

@MichalJZ

Description

@MichalJZ

Hi there! 👋

I noticed that there's a bug where Chrome on iOS is being incorrectly identified as Safari 11, causing unnecessary polyfills to be loaded for modern browsers. Chrome on iOS is being misclassified as Safari 11 due to the order of user agent detection logic in useragent.rs, which results in loading excessive polyfills for modern browsers that don't need them, potentially causing production issues. We observe problem with react-router redirect because of loading AbortController polyfill.

Root Cause

In library/src/useragent.rs, the detection logic uses if-else statements where:

  1. Lines 46-200: Mobile Safari detection uses regex (iPod|iPhone|iPad).+AppleWebKit\/605\.1(?:\.\d+|)
  2. Line 2180: Correct Chrome mobile detection logic

The Safari regex incorrectly matches Chrome on iOS user agents, preventing the correct Chrome detection from running.

Example Problematic User Agent

Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/92.0.4515.90 Mobile/15E148 Safari/604.1

According to documentation, the difference between Chrome and Safari user agents on iOS is minimal, but this case should be handled correctly.

Current Impact

  • Chrome on iOS (modern versions) receives polyfills intended for Safari 11
  • Can cause runtime errors in production environments
  • Affects performance due to loading unneeded code

Expected Behavior

Chrome on iOS should be correctly identified with its actual version number and receive appropriate polyfills for that version.

Reproduction Steps

  1. Use Chrome on iOS User Agent
  2. Request polyfills from the service
  3. Observe that polyfills for Safari 11 are returned instead of Chrome-appropriate polyfills

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions