Skip to content

Commit

Permalink
Add support for Chrome and Safari to DestinationEnvironment (#228)
Browse files Browse the repository at this point in the history
Ref #227. Not sure if `.edge` is intended to represent Chrome-Edge or legacy Edge.
  • Loading branch information
j-f1 committed May 28, 2021
1 parent 18113a1 commit 7204aa4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Sources/CartonKit/Server/Environment+UserAgent.swift
Expand Up @@ -16,8 +16,21 @@ import SwiftToolchain

extension DestinationEnvironment {
init?(userAgent: String) {
guard userAgent.contains("Firefox") else { return nil }
if userAgent.contains("Firefox") {
self = .firefox
}
// Edge UA string contains `Chrome` and `Safari` so this must go first
if userAgent.contains("Edg/") {
self = .edge
}
// Chrome UA string contains `Safari` so this must go first
if userAgent.contains("Chrome/") {
self = .chrome
}
if userAgent.contains("Safari/") {
self = .safari
}

self = .firefox
return nil
}
}

0 comments on commit 7204aa4

Please sign in to comment.