Skip to content

Commit 6c33f68

Browse files
committed
Truncate browser context hardwareConcurrency value
We have received reports of some UAs providing this value as a floating point rather than integral value (contrary to the web standards). This causes events from those agents to be invalid because the schema requires it to be an integer. To meet the documented behavior and schema expectations, floor the value to ensure it is a whole integer. If the UA doesn't have this value, Math.floor should return NaN which we will turn into undefined to exclude from the event. This will also occur with '0', which shouldn't be a valid value according to the standard anyway so is deemed acceptable. Issue: AISP-629
1 parent ca65906 commit 6c33f68

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker-core",
5+
"comment": "Truncate browser context hardwareConcurrency value to prevent invalid events",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker-core"
10+
}

libraries/browser-tracker-core/src/helpers/browser_props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function readBrowserProperties(): BrowserProperties {
8686
documentLanguage: document.documentElement.lang,
8787
webdriver: window.navigator.webdriver,
8888
deviceMemory: (window.navigator as any).deviceMemory,
89-
hardwareConcurrency: (window.navigator as any).hardwareConcurrency,
89+
hardwareConcurrency: Math.floor(window.navigator.hardwareConcurrency) || undefined,
9090
};
9191
}
9292

0 commit comments

Comments
 (0)