Skip to content

Commit

Permalink
fix: fix platformVersion default value (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush authored Aug 23, 2024
1 parent 415e02c commit d7878c0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/userAgentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export function getClientHintsAgent(osData?: UADataValues): AgentInfo {
const chromiumBrand = findPresetBrand(CHROMIUM_PRESETS, brands);

browser.chromium = !!chromiumBrand.brand;
browser.chromiumVersion = chromiumBrand.version;
browser.chromiumVersion = chromiumBrand.version || "-1";
if (!browser.chromium) {
const webkitBrand = findPresetBrand(WEBKIT_PRESETS, brands);

browser.webkit = !!webkitBrand.brand;
browser.webkitVersion = webkitBrand.version;
browser.webkitVersion = webkitBrand.version || "-1";
}

const platfomResult = find(OS_PRESETS, preset => {
Expand All @@ -44,7 +44,7 @@ export function getClientHintsAgent(osData?: UADataValues): AgentInfo {
os.name = platfomResult ? platfomResult.id : "";

if (osData) {
os.version = osData.platformVersion;
os.version = osData.platformVersion || "-1";
}
if (fullVersionList && fullVersionList.length) {
const browserBrandByFullVersionList = findPresetBrand(BROWSER_PRESETS, fullVersionList);
Expand Down
48 changes: 48 additions & 0 deletions test/unit/userAgentDataConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,54 @@ const AGENT_DATA_LIST = [
},
},
},
{
name: "Mac && Chrome 100 (NO Version)",
platform: "macOS",
osData: {
architecture: "x86",
model: "",
platform: "macOS",
uaFullVersion: "100.0.4896.127",
fullVersionList: [
{ brand: `"Not;A\\Brand`, version: "99.0.0.0" },
{ brand: "Chromium", version: "100.0.4896.127" },
{ brand: "Google Chrome", version: "100.0.4896.127" },
],
},
userAgentData: {
brands: [
{ brand: `"Not;A\\Brand`, version: "99" },
{ brand: "Chromium", version: "100" },
{ brand: "Google Chrome", version: "100" },
],
mobile: false,
platform: "macOS",
},
result: {
os: {
name: "mac",
version: "-1",
},
browser: {
name: "chrome",
version: "100",
chromium: true,
webkit: false,
chromiumVersion: "100",
webkitVersion: "-1",
},
isMobile: false,
},
accurateResult: {
os: {
name: "mac",
version: "-1",
},
browser: {
version: "100.0.4896.127",
},
},
},
];

export default AGENT_DATA_LIST;

0 comments on commit d7878c0

Please sign in to comment.