Skip to content

Commit

Permalink
fix: parse Safari versions correctly in generator-networks-creator (#…
Browse files Browse the repository at this point in the history
…347)

The `generator-networks-creator` package is parsing the browser versions from the `user-agent` string. 

While other browsers use the `chrome/130.0.0.0` suffix in the `user-agent` string, Safari uses the `Version/18.0 Safari/650.0.0.0` syntax - with `650.0.0.0` being the WebKit, not the Safari version.

This PR fixes this omission in `generator-networks-creator` and regenerates the generative models. There is also minor refactoring.
  • Loading branch information
barjin authored Jan 6, 2025
1 parent 92611df commit 6675262
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +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 supportedBrowsers = /(firefox|fxios|chrome|crios|safari)\/([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 All @@ -144,7 +145,14 @@ export class GeneratorNetworksCreator {
if (edge.test(userAgent)) {
const match = userAgent.match(edge)![0].split('/');
return `edge/${match[1]}`;
} if (supportedBrowsers.test(userAgent)) {
}

if (safari.test(userAgent)) {
const match = userAgent.match(safari);
return `safari/${match![1]}`;
}

if (supportedBrowsers.test(userAgent)) {
const match = userAgent.match(supportedBrowsers)![0].split('/');
return `${canonicalNames[match[0].toLowerCase()]}/${match[1]}`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["chrome/128.0.0.0|2","chrome/130.0.0.0|2","chrome/120.0.0.0|2","edge/130.0.0.0|2","chrome/129.0.0.0|2","safari/605.1.15|2","chrome/124.0.0.0|2","*MISSING_VALUE*|2","chrome/126.0.0.0|2","safari/604.1|2","firefox/132.0|2","chrome/109.0.0.0|2","chrome/130.0.6723.78|2","firefox/66.0|2","chrome/130.0.6723.90|2","firefox/131.0|2","chrome/132.0.0.0|2","chrome/130.0.0.0|1","chrome/130.0.6723.37|2","chrome/116.0.0.0|2","chrome/122.0.0.0|2","chrome/123.0.0.0|2","chrome/131.0.0.0|2","chrome/127.0.0.0|2","chrome/104.0.5112.79|2","edge/129.0.0.0|2","chrome/94.0.4606.114|2","chrome/129.0.0.0|1","firefox/128.0|2","chrome/126.0.6478.806|2","chrome/121.0.0.0|2","chrome/112.0.5615.213|2","chrome/79.0.3945.117|1","chrome/113.0.0.0|2","chrome/118.0.0.0|2","chrome/117.0.0.0|2","chrome/115.0.0.0|2","chrome/79.0.3945.79|2","chrome/125.0.6422.26|2","safari/605.1.15|1","edge/130.0.0.0|1","chrome/114.0.0.0|2","firefox/130.0|2","chrome/119.0.0.0|2","chrome/105.0.0.0|2","chrome/130.0.6723.86|2","chrome/129.0.6668.46|2","firefox/133.0|2","chrome/93.0.4577.100|2","firefox/118.0|2","chrome/125.0.0.0|2","chrome/106.0.0.0|1","chrome/106.0.0.0|2","firefox/131.0|1","chrome/125.0.6422.80|2","safari/604.1|1","firefox/129.0|2","edge/120.0.0.0|2","firefox/124.0|2","firefox/125.0|2","edge/128.0.0.0|2","chrome/130.0.6723.58|2","firefox/113.0|2","edge/131.0.0.0|2","edge/92.0.902.67|2","chrome/112.0.0.0|2","chrome/94.0.4606.71|2","chrome/90.0.4430.216|2","*MISSING_VALUE*|1","chrome/88.0.4324.150|2","firefox/134.0|2","chrome/92.0.4515.107|2","chrome/94.0.4590.2|2","chrome/108.0.0.0|2","chrome/90.0.4430.93|2","chrome/83.0.4103.116|2","chrome/121.0.0.0|1","edge/129.0.2792.92|2","edge/129.0.0.0|1","chrome/97.0.4692.99|2","chrome/101.0.4951.15|2","chrome/129.0.6668.100|2","chrome/128.0.0.0|1","firefox/115.0|2","chrome/103.0.0.0|2","edge/130.0.2849.57|2","chrome/110.0.0.0|2","firefox/129.1|2","chrome/122.0.6261.171|2","chrome/127.0.6533.17|2","chrome/128.0.6613.34|2","chrome/128.0.6613.92|2","chrome/109.0.5414.120|2","edge/126.0.0.0|2","chrome/122.0.6261.112|2","firefox/117.0|2","chrome/126.0.6478.153|2","chrome/103.0.5060.129|2","edge/122.0.0.0|2","firefox/128.0|1","firefox/127.0|2","chrome/118.0.5993.220|2","firefox/95.0|2","chrome/124.0.6367.71|2","edge/114.0.1823.51|2","chrome/107.0.0.0|2","chrome/110.0.5481.153|2","firefox/131.4|2","firefox/126.0|2","chrome/111.0.0.0|2","chrome/92.0.4515.131|2","edge/128.0.0.0|1","edge/126.0.2592.106|2","chrome/100.0.4896.58|2","chrome/129.0.6668.69|2","chrome/91.0.4472.124|2","chrome/86.0.4240.75|2","safari/600.1.4|2","chrome/88.0.4324.182|2","edge/124.0.2478.64|2","edge/109.0.1518.140|2","chrome/109.0.0.0|1","chrome/127.0.6533.107|2","firefox/122.0|2","edge/130.0.2849.52|2","safari/602.1|2","chrome/59.0.3071.125|2","edge/127.0.0.0|2","chrome/132.0.0.0|1","chrome/127.0.0.0|1","chrome/128.0.6613.146|2","chrome/95.0.4638.69|2","chrome/128.0.6613.98|2","firefox/123.0|2","chrome/75.0.3770.156|2","chrome/124.0.6315.2|2","edge/100.0.1185.36|2","firefox/129|2","chrome/91.0.4472.114|2","chrome/91.0.4472.120|2","chrome/87.0.4280.141|2","chrome/122.0.6261.95|2","chrome/130.0.6723.58|1","chrome/120.0.6099.119|2","chrome/74.0.3729.136|2","firefox/114.0|2","chrome/108.0.5359.112|2","chrome/60.0.4574.1295|2","chrome/98.0.4758.87|2","chrome/128.0.6613.551|2","chrome/129.0.6668.102|2","chrome/115.0.5790.24|2","chrome/85.0.4183.101|2","edge/127.0.0.0|1","firefox/131|2","chrome/63.0.3239.111|2","edge/130.0.2849.46|2","chrome/91.0.4472.101|2","chrome/119.0.6045.193|2","edge/124.0.0.0|2","chrome/87.0.4280.101|2","chrome/127.0.6533.122|2","chrome/89.0.4389.130|2","chrome/130.0.6723.24|2","chrome/99.0.4844.88|2","chrome/116.0.5845.177|2","chrome/79.0.3945.88|2","chrome/123.0.6312.52|2","edge/125.0.0.0|2","chrome/120.0.6099.101|2","edge/121.0.0.0|2","chrome/131.0.6778.14|2","chrome/130.0.6723.73|2","firefox/131.1|2","chrome/56.0.2237.1637|2","chrome/129.0.6668.82|2","chrome/94.0.4606.61|2","chrome/130.0.6723.60|2","chrome/91.0.4472.164|2"]
["chrome/131.0.0.0|2","chrome/131.0.6778.154|2","chrome/120.0.0.0|2","chrome/128.0.0.0|2","safari/18.2|2","safari/18.0|2","chrome/131.0.6778.134|2","firefox/133.0|2","safari/17.6|2","chrome/122.0.0.0|2","chrome/124.0.0.0|2","*MISSING_VALUE*|2","chrome/130.0.0.0|2","chrome/131.0.6778.33|2","chrome/131.0.0.0|1","edge/132.0.0.0|2","edge/131.0.0.0|2","safari/16.6|2","safari/15.6.6|2","chrome/133.0.0.0|2","chrome/63.0.3239.111|2","safari/16.3|2","chrome/127.0.0.0|2","chrome/126.0.0.0|2","safari/18.0.1|2","safari/18.1.1|2","safari/18.1|2","safari/18.3|2","edge/131.0.0.0|1","chrome/131.0.6778.135|2","firefox/128.0|2","firefox/119.0|2","safari/16.0|2","edge/131.0.2903.125|2","chrome/120.0.6099.193|2","chrome/125.0.0.0|2","chrome/96.0.4664.104|2","chrome/123.0.0.0|2","safari/17.5|2","chrome/120.0.0.0|1","edge/129.0.0.0|2","firefox/127.0|2","chrome/119.0.0.0|2","safari/17.5|1","chrome/109.0.0.0|2","safari/604.1|2","chrome/129.0.0.0|2","safari/17.4.1|2","chrome/125.0.6422.26|2","chrome/121.0.0.0|2","chrome/117.0.0.0|2","chrome/114.0.0.0|2","firefox/132.0|2","edge/124.0.0.0|2","chrome/115.0.0.0|2","safari/17.1|2","chrome/130.0.0.0|1","safari/17.1.1|2","firefox/126.0|2","chrome/132.0.0.0|2","chrome/130.0.6723.103|2","chrome/116.0.0.0|2","chrome/113.0.0.0|2","chrome/99.0.4844.88|2","chrome/57.0.2987.110|2","safari/17.2|2","chrome/87.0.4280.141|2","chrome/114.0.5735.196|2","safari/17.3|2","safari/17.2.1|2","chrome/104.0.5112.88|2","chrome/107.0.5304.66|2","chrome/131.0.6778.136|2","edge/126.0.0.0|2","firefox/115.0|2","chrome/126.0.0.0|1","chrome/91.0.4472.124|2","firefox/133.4|2","safari/16.1|2","chrome/131.0.6778.73|2","safari/17.3.1|1","safari/17.4|2","chrome/121.0.0.0|1","safari/17.0|2","safari/17.3.1|2","chrome/90.0.4430.93|2","chrome/118.0.0.0|2","chrome/111.0.0.0|2","chrome/123.0.6312.118|2","safari/17.1.2|2","chrome/103.0.0.0|2","chrome/72.0.3626.121|2","chrome/75.0.3770.156|2","firefox/134.0|2","chrome/44.0.6226.1030|2","chrome/88.0.4324.182|2","safari/17.8|2","edge/123.0.0.0|2","chrome/131.0.6778.200|2","safari/16.4|2","safari/14.1.1|2","chrome/131.0.6778.131|2","chrome/120.0.6099.119|2","chrome/104.0.0.0|2","firefox/133.0|1","chrome/79.0.3945.117|1","safari/16.6.1|2","chrome/131.0.6778.139|1","chrome/92.0.4515.131|2","chrome/112.0.0.0|2","chrome/94.0.4590.2|2","safari/11.0|2","firefox/130.0|2","edge/130.0.0.0|2","chrome/122.0.6261.95|2","firefox/129.0|2","chrome/91.0.4472.120|2","edge/131.0.2903.112|2","chrome/108.0.0.0|2","safari/16.5.2|2","safari/17.8.1|2","edge/133.0.0.0|2","safari/15.6.1|2","chrome/115.0.5790.130|2","chrome/107.0.0.0|2","safari/15.6|2","firefox/135.0|2","chrome/131.0.6778.103|2","edge/127.0.0.0|2","chrome/94.0.4606.114|2","chrome/128.0.6613.186|2","chrome/131.0.6778.41|2","safari/16.2|2","*MISSING_VALUE*|1","safari/8613.1.17.0.8|2","safari/16.5|2","firefox/131.0|2","safari/15.4|2","chrome/119.0.6045.193|2","chrome/130.0.6723.142|2","chrome/57.0.1716.1704|2","chrome/121.0.6167.171|2","chrome/86.0.4240.198|2","firefox/133|2","firefox/109.0|2","safari/17.7|2","chrome/59.0.3071.125|2","safari/10.0|2","chrome/92.0.4515.107|2","edge/122.0.0.0|2","firefox/96.0|2","chrome/110.0.0.0|2","chrome/126.0.6478.61|2","chrome/129.0.6668.101|2","chrome/112.0.5615.213|2","edge/119.0.0.0|2","chrome/131.0.6628.82|2","chrome/118.0.5993.220|2","chrome/109.0.5414.118|2","safari/605.1.15|2","safari/17.6.1|2","chrome/117.0.5938.104|2","firefox/120.0|2","chrome/127.0.6533.0|2","safari/18.2|1","safari/16.5.1|2","chrome/131.0.6778.140|2","chrome/43.0.6549.1152|2","chrome/126.0.6478.188|2","chrome/121.0.6167.66|2","chrome/98.0.4758.102|2","chrome/123.0.6312.52|2","safari/17.7.1|2","chrome/70.0.3538.110|2","safari/15.5|2","chrome/124.0.6367.111|2","chrome/126.0.6478.153|2","chrome/83.0.4103.101|2","edge/128.0.0.0|2","chrome/105.0.0.0|2","firefox/110.0|2","edge/109.0.1518.140|2","safari/16.4.1|2","firefox/128.0|1","chrome/109.0.5414.120|2","chrome/124.0.0.0|1","edge/18.17763|2","edge/113.0.1774.57|2","safari/16.6|1","edge/124.0.2478.64|2"]
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions packages/header-generator/src/header-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface HeaderGeneratorOptions {
httpVersion: HttpVersion;
/**
* If true, the generator will throw an error if it cannot generate headers based on the input.
*
* By default (strict: false), the generator will try to relax some requirements and generate headers based on the relaxed input.
*/
strict: boolean;
}
Expand Down Expand Up @@ -380,8 +382,10 @@ export class HeaderGenerator {
for (const browser of browsers) {
for (const browserOption of this.uniqueBrowsers) {
if (browser.name === browserOption.name) {
if ((!browser.minVersion || this._browserVersionIsLesserOrEquals([browser.minVersion], browserOption.version))
&& (!browser.maxVersion || this._browserVersionIsLesserOrEquals(browserOption.version, [browser.maxVersion]))
const browserMajorVersion = browserOption.version[0];

if ((!browser.minVersion || browser.minVersion <= browserMajorVersion)
&& (!browser.maxVersion || browser.maxVersion >= browserMajorVersion)
&& browser.httpVersion === browserOption.httpVersion) {
browserHttpOptions.push(browserOption.completeString);
}
Expand Down Expand Up @@ -510,8 +514,4 @@ export class HeaderGenerator {

return (this.headersOrder as Record<string, any>)[browser] ?? [];
}

private _browserVersionIsLesserOrEquals(browserVersionL: number[], browserVersionR: number[]) {
return browserVersionL[0] <= browserVersionR[0];
}
}
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 6675262

Please sign in to comment.