Removed parameters from navigator functions

This commit is contained in:
z0ccc 2021-10-05 00:03:35 -04:00
parent 9a308f287a
commit cca0a0e02e

View file

@ -1,153 +1,192 @@
import { checkWebWorker } from './common'; import { checkWebWorker } from './common';
const getDeviceMemory = (key, worker) => ({ const getDeviceMemory = (worker) => {
key: 'Device memory', const name = 'deviceMemory';
code: `navigator.${key}`, return {
value: navigator[key], key: 'Device memory',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
checkWebWorker(navigator[key], worker), checkNavigatorValue(name),
], checkNavigatorPrototype(name),
}); checkWebWorker(navigator[name], worker),
],
};
};
const getHardwareConcurrency = (key, worker) => ({ const getHardwareConcurrency = (worker) => {
key: 'Hardware concurrency', const name = 'hardwareConcurrency';
code: `navigator.${key}`, return {
value: navigator[key], key: 'Hardware concurrency',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
checkWebWorker(navigator[key], worker), checkNavigatorValue(name),
], checkNavigatorPrototype(name),
}); checkWebWorker(navigator[name], worker),
],
};
};
const getMaxTouchPoints = (key) => ({ const getMaxTouchPoints = () => {
key: 'Max touch points', const name = 'maxTouchPoints';
code: `navigator.${key}`, return {
value: navigator[key], key: 'Max touch points',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
const getPlatform = (key, worker) => ({ const getPlatform = (worker) => {
key: 'Platform', const name = 'platform';
code: `navigator.${key}`, return {
value: navigator[key], key: 'Platform',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
checkWebWorker(navigator[key], worker), checkNavigatorValue(name),
], checkNavigatorPrototype(name),
}); checkWebWorker(navigator[name], worker),
],
};
};
const getUserAgent = (key, worker) => ({ const getUserAgent = (worker) => {
key: 'User agent', const name = 'userAgent';
code: `navigator.${key}`, return {
value: navigator[key], key: 'User agent',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
checkWebWorker(navigator[key], worker), checkNavigatorValue(name),
], checkNavigatorPrototype(name),
}); checkWebWorker(navigator[name], worker),
],
};
};
const getAppVersion = (key, worker) => ({ const getAppVersion = (worker) => {
key: 'App version', const name = 'appVersion';
code: `navigator.${key}`, return {
value: navigator[key], key: 'App version',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
checkWebWorker(navigator[key], worker), checkNavigatorValue(name),
], checkNavigatorPrototype(name),
}); checkWebWorker(navigator[name], worker),
],
};
};
const getLanguage = (key, worker) => ({ const getLanguage = (worker) => {
key: 'Language', const name = 'language';
code: `navigator.${key}`, return {
value: navigator[key], key: 'Language',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
checkWebWorker(navigator[key], worker), checkNavigatorValue(name),
], checkNavigatorPrototype(name),
}); checkWebWorker(navigator[name], worker),
],
};
};
const getLanguages = (key) => ({ const getLanguages = () => {
key: 'Languages', const name = 'languages';
code: `navigator.${key}`, return {
value: sortArr(navigator[key]), key: 'Languages',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: sortArr(navigator[name]),
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
const getCookieEnabled = (key) => ({ const getCookieEnabled = () => {
key: 'Cookie enabled', const name = 'cookieEnabled';
code: `navigator.${key}`, return {
value: navigator[key] ? 'True' : 'False', key: 'Cookie enabled',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name] ? 'True' : 'False',
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
const getDoNotTrack = (key) => ({ const getDoNotTrack = () => {
key: 'Do not track', const name = 'doNotTrack';
code: `navigator.${key}`, return {
value: navigator[key] ? 'True' : 'False', key: 'Do not track',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name] ? 'True' : 'False',
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
const getWebDriver = (key) => ({ const getWebDriver = () => {
key: 'Web driver', const name = 'webdriver';
code: `navigator.${key}`, return {
value: navigator[key] ? 'True' : 'False', key: 'Web driver',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name] ? 'True' : 'False',
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
const getPlugins = (key) => ({ const getPlugins = () => {
key: 'Plugins', const name = 'plugins';
code: `navigator.${key}`, return {
value: sortPlugins(navigator[key]), key: 'Plugins',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: sortPlugins(navigator[name]),
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
const getVendor = (key) => ({ const getVendor = () => {
key: 'Vendor', const name = 'vendor';
code: `navigator.${key}`, return {
value: navigator[key], key: 'Vendor',
issues: [ code: `navigator.${name}`,
checkNavigatorProperties(key), value: navigator[name],
checkNavigatorValue(key), issues: [
checkNavigatorPrototype(key), checkNavigatorProperties(name),
], checkNavigatorValue(name),
}); checkNavigatorPrototype(name),
],
};
};
// sorts array into comma separated list // sorts array into comma separated list
const sortArr = (arr) => { const sortArr = (arr) => {
@ -172,27 +211,30 @@ const sortPlugins = (data) => {
return list; return list;
}; };
const checkNavigatorProperties = (key) => { const checkNavigatorProperties = (name) => {
if (Object.getOwnPropertyDescriptor(navigator, key) !== undefined) { if (Object.getOwnPropertyDescriptor(navigator, name) !== undefined) {
return 'Failed undefined properties'; return 'Failed undefined properties';
} }
return null; return null;
}; };
const checkNavigatorValue = (key) => { const checkNavigatorValue = (name) => {
try { try {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const { value } = Object.getOwnPropertyDescriptor(Navigator.prototype, key); const { value } = Object.getOwnPropertyDescriptor(
Navigator.prototype,
name
);
} catch (err) { } catch (err) {
return 'Failed Navigator property value'; return 'Failed Navigator property value';
} }
return null; return null;
}; };
const checkNavigatorPrototype = (key) => { const checkNavigatorPrototype = (name) => {
try { try {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const check = Navigator.prototype[key]; const check = Navigator.prototype[name];
return 'Failed Navigator.prototype'; return 'Failed Navigator.prototype';
} catch (err) { } catch (err) {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -202,19 +244,19 @@ const checkNavigatorPrototype = (key) => {
}; };
const getNavigator = (workerData) => [ const getNavigator = (workerData) => [
getDeviceMemory('deviceMemory', workerData.deviceMemory), getDeviceMemory(workerData.deviceMemory),
getHardwareConcurrency('hardwareConcurrency', workerData.hardwareConcurrency), getHardwareConcurrency(workerData.hardwareConcurrency),
getMaxTouchPoints('maxTouchPoints'), getMaxTouchPoints(),
getPlatform('platform', workerData.platform), getPlatform(workerData.platform),
getUserAgent('userAgent', workerData.userAgent), getUserAgent(workerData.userAgent),
getAppVersion('appVersion', workerData.appVersion), getAppVersion(workerData.appVersion),
getLanguage('language', workerData.language), getLanguage(workerData.language),
getLanguages('languages'), getLanguages(),
getCookieEnabled('cookieEnabled'), getCookieEnabled(),
getDoNotTrack('doNotTrack'), getDoNotTrack(),
getWebDriver('webdriver'), getWebDriver(),
getPlugins('plugins'), getPlugins(),
getVendor('vendor'), getVendor(),
]; ];
export default getNavigator; export default getNavigator;