diff --git a/frontend/src/components/OtherBlock.js b/frontend/src/components/OtherBlock.js index 319c827..fe2ade8 100644 --- a/frontend/src/components/OtherBlock.js +++ b/frontend/src/components/OtherBlock.js @@ -20,9 +20,13 @@ const OtherBlock = ({ workerData }) => { .catch(() => { setAdBlock(true); }); - navigator.getBattery().then((res) => { - setBattery(res); - }); + if ('getBattery' in navigator) { + navigator.getBattery().then((res) => { + setBattery(res); + }); + } else { + setBattery('N/A'); + } }, []); return ( diff --git a/frontend/src/utils/navigator.js b/frontend/src/utils/navigator.js index 8413e1d..6c36c5b 100644 --- a/frontend/src/utils/navigator.js +++ b/frontend/src/utils/navigator.js @@ -157,11 +157,11 @@ const checkNavigatorProperties = (key) => { }; const checkNavigatorValue = (key) => { - if ( - Object.getOwnPropertyDescriptor(Navigator.prototype, key).value !== - undefined - ) { - return 'Failed descriptor.value undefined'; + try { + // eslint-disable-next-line no-unused-vars + const { value } = Object.getOwnPropertyDescriptor(Navigator.prototype, key); + } catch (err) { + return 'Failed Navigator.prototype'; } return null; }; diff --git a/frontend/src/utils/other.js b/frontend/src/utils/other.js index 545b837..8396fd8 100644 --- a/frontend/src/utils/other.js +++ b/frontend/src/utils/other.js @@ -21,45 +21,58 @@ const checkDatePrototype = () => { }; // Returns object with location data -const getOther = (battery, adBlock, workerData) => [ - { - key: 'Brave browser', - value: navigator.brave ? 'True' : 'False', - issues: [], - }, - { - key: 'Tor browser', - value: detectTor() ? 'True' : 'False', - issues: [], - }, - { - key: 'Adblock', - value: adBlock ? 'True' : 'False', - issues: [], - }, - { - key: 'Date', - value: new Date().toString(), - issues: [checkDatePrototype()], - }, - { - key: 'Timezone offset', - value: new Date().getTimezoneOffset(), - issues: [ - checkDatePrototype(), - checkWebWorker(new Date().getTimezoneOffset(), workerData.timezoneOffset), - ], - }, - { - key: 'Battery level', - value: `${Math.round(battery.level * 100)}%`, - issues: [], - }, - { - key: 'Battery status', - value: battery.charging ? 'Charging' : 'Not charging', - issues: [], - }, -]; - +const getOther = (battery, adBlock, workerData) => { + console.log(battery); + let batteryLevel, batteryStatus; + if (battery === 'N/A') { + batteryLevel = 'N/A'; + batteryStatus = 'N/A'; + } else { + batteryLevel = `${Math.round(battery.level * 100)}%`; + batteryStatus = battery.charging ? 'Charging' : 'Not charging'; + } + return [ + { + key: 'Brave browser', + value: navigator.brave ? 'True' : 'False', + issues: [], + }, + { + key: 'Tor browser', + value: detectTor() ? 'True' : 'False', + issues: [], + }, + { + key: 'Adblock', + value: adBlock ? 'True' : 'False', + issues: [], + }, + { + key: 'Date', + value: new Date().toString(), + issues: [checkDatePrototype()], + }, + { + key: 'Timezone offset', + value: new Date().getTimezoneOffset(), + issues: [ + checkDatePrototype(), + checkWebWorker( + new Date().getTimezoneOffset(), + workerData.timezoneOffset + ), + ], + }, + { + key: 'Battery level', + value: batteryLevel, + issues: [], + }, + { + key: 'Battery status', + value: batteryStatus, + issues: [], + }, + ]; +}; export default getOther;