Skip to content

Commit

Permalink
fix: better Safari user-agent parsing, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Jan 6, 2025
1 parent 8f7981c commit e6ce478
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export class GeneratorNetworksCreator {
edgios: 'edge',
} as Record<string, string>;

const unsupportedBrowsers = /opr|yabrowser|SamsungBrowser|UCBrowser|vivaldi/ig;
const edge = /(edg(a|ios|e)?)\/([0-9.]*)/ig;
const safari = /Version\/([\d.]+) Safari/i;
const supportedBrowsers = /(firefox|fxios|chrome|crios)\/([0-9.]*)/ig;
const unsupportedBrowsers = /opr|yabrowser|SamsungBrowser|UCBrowser|vivaldi/i;
const edge = /(edg(a|ios|e)?)\/([0-9.]*)/i;
const safari = /Version\/([\d.]+)( Mobile\/[a-z0-9]+)? Safari/i;
const supportedBrowsers = /(firefox|fxios|chrome|crios|safari)\/([0-9.]*)/i;

if (unsupportedBrowsers.test(userAgent)) {
return missingValueDatasetToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ describe('Processing browser data', () => {
},
{
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1",
expectedBrowser: "safari/604.1",
expectedBrowser: "safari/16.5",
expectedOS: "ios",
expectedDeviceType: "mobile"
},
{
userAgent: "Mozilla/5.0 (iPad; CPU OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1",
expectedBrowser: "safari/604.1",
expectedBrowser: "safari/16.5",
expectedOS: "ios",
expectedDeviceType: "mobile"
},
{
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15",
expectedBrowser: "safari/605.1.15",
expectedBrowser: "safari/16.5",
expectedOS: "macos",
expectedDeviceType: "desktop"
},
Expand Down

0 comments on commit e6ce478

Please sign in to comment.