Fixed battery errors on firefox
This commit is contained in:
parent
680d416ce0
commit
f33c3686ba
3 changed files with 66 additions and 49 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue