Fixed web worker
This commit is contained in:
parent
c150fa384f
commit
5b7a28fd61
6 changed files with 89 additions and 49 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-scripts": "4.0.3",
|
"react-scripts": "4.0.3",
|
||||||
"react-tsparticles": "^1.28.0",
|
"react-tsparticles": "^1.28.0",
|
||||||
|
"react-webworker": "^2.1.0",
|
||||||
"tslib": "^2.2.0"
|
"tslib": "^2.2.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -1 +1,5 @@
|
||||||
postMessage('hello');
|
/* eslint-disable import/prefer-default-export */
|
||||||
|
onmessage = (e) => {
|
||||||
|
console.log(e.data, navigator[e.data]);
|
||||||
|
postMessage(navigator[e.data]);
|
||||||
|
};
|
||||||
|
|
|
||||||
23
frontend/src/components/Issues.js
Normal file
23
frontend/src/components/Issues.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
import parse from 'html-react-parser';
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import { checkUndefinedProperties, checkWebWorker } from './navigator';
|
||||||
|
|
||||||
|
const Issues = ({ item }) => {
|
||||||
|
const [workerData, setWorkerData] = useState();
|
||||||
|
useEffect(() => {
|
||||||
|
checkWebWorker(item, setWorkerData);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td>
|
||||||
|
{parse(checkUndefinedProperties(item))}
|
||||||
|
<br />
|
||||||
|
<>{workerData}</>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
|
||||||
|
// return <td>{parse(checkUndefinedProperties(item), workerData)}</td>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Issues;
|
||||||
|
|
@ -1,20 +1,27 @@
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
import parse from 'html-react-parser';
|
import parse from 'html-react-parser';
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
import { checkUndefinedProperties } from './navigator';
|
import { checkUndefinedProperties } from './navigator';
|
||||||
|
import Issues from './Issues';
|
||||||
|
|
||||||
const Table = ({ data }) => (
|
const Table = ({ data }) => {
|
||||||
<div className="tableWrap">
|
const [workerData, setWorkerData] = useState();
|
||||||
<table>
|
|
||||||
{data.map((item) => (
|
return (
|
||||||
<tbody key={item.key}>
|
<div className="tableWrap">
|
||||||
<tr>
|
<table>
|
||||||
<td>{item.title}</td>
|
{data.map((item) => (
|
||||||
<td>{item.value}</td>
|
<tbody key={item.key}>
|
||||||
<td>{parse(checkUndefinedProperties(item))}</td>
|
<tr>
|
||||||
</tr>
|
<td>{item.title}</td>
|
||||||
</tbody>
|
<td>{item.value}</td>
|
||||||
))}
|
<Issues item={item} />
|
||||||
</table>
|
</tr>
|
||||||
</div>
|
</tbody>
|
||||||
);
|
))}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default Table;
|
export default Table;
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,42 @@
|
||||||
/* eslint-disable dot-notation */
|
/* eslint-disable dot-notation */
|
||||||
export { getNavigator, checkUndefinedProperties };
|
export { getNavigator, checkUndefinedProperties, checkWebWorker };
|
||||||
|
|
||||||
const getNavigator = () => {
|
const getNavigator = () => {
|
||||||
const data = [
|
const data = [
|
||||||
{
|
{
|
||||||
key: 'deviceMemory',
|
key: 'deviceMemory',
|
||||||
title: 'Device memory',
|
title: 'Device memory',
|
||||||
value: navigator.deviceMemory || 'N/A',
|
value: navigator.deviceMemory,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'hardwareConcurrency',
|
key: 'hardwareConcurrency',
|
||||||
title: 'Hardware Concurrency',
|
title: 'Hardware Concurrency',
|
||||||
value: navigator.hardwareConcurrency || 'N/A',
|
value: navigator.hardwareConcurrency,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'maxTouchPoints',
|
key: 'maxTouchPoints',
|
||||||
title: 'Max touchpoints',
|
title: 'Max touchpoints',
|
||||||
value: navigator.maxTouchPoints || 'N/A',
|
value: navigator.maxTouchPoints,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'platform',
|
key: 'platform',
|
||||||
title: 'Platform',
|
title: 'Platform',
|
||||||
value: navigator.platform || 'N/A',
|
value: navigator.platform,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'userAgent',
|
key: 'userAgent',
|
||||||
title: 'User agent',
|
title: 'User agent',
|
||||||
value: navigator.userAgent || 'N/A',
|
value: navigator.userAgent,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'language',
|
key: 'language',
|
||||||
title: 'Language',
|
title: 'Language',
|
||||||
value: navigator.language || 'N/A',
|
value: navigator.language,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'languages',
|
key: 'languages',
|
||||||
title: 'Languages',
|
title: 'Languages',
|
||||||
value: navigator.languages || 'N/A',
|
value: navigator.languages,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'cookieEnabled',
|
key: 'cookieEnabled',
|
||||||
|
|
@ -56,30 +56,30 @@ const getNavigator = () => {
|
||||||
{
|
{
|
||||||
key: 'plugins',
|
key: 'plugins',
|
||||||
title: 'Plugins',
|
title: 'Plugins',
|
||||||
value: sortPlugins(navigator.plugins) || 'N/A',
|
value: sortPlugins(navigator.plugins),
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// key: 'connection',
|
// key: 'connection',
|
||||||
// title: 'Connection',
|
// title: 'Connection',
|
||||||
// value: JSON.stringify(navigator.connection) || 'N/A',
|
// value: JSON.stringify(navigator.connection),
|
||||||
// prototype: Navigator.prototype.hardwareConcurrency,
|
// prototype: Navigator.prototype.hardwareConcurrency,
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// key: 'geolocation',
|
// key: 'geolocation',
|
||||||
// title: 'Geolocation',
|
// title: 'Geolocation',
|
||||||
// value: navigator.geolocation || 'N/A',
|
// value: navigator.geolocation,
|
||||||
// prototype: Navigator.prototype.hardwareConcurrency,
|
// prototype: Navigator.prototype.hardwareConcurrency,
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// key: 'hid',
|
// key: 'hid',
|
||||||
// title: 'Hid',
|
// title: 'Hid',
|
||||||
// value: navigator.hid || 'N/A',
|
// value: navigator.hid,
|
||||||
// prototype: Navigator.prototype.hardwareConcurrency,
|
// prototype: Navigator.prototype.hardwareConcurrency,
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// key: 'keyboard',
|
// key: 'keyboard',
|
||||||
// title: 'Keyboard',
|
// title: 'Keyboard',
|
||||||
// value: navigator.keyboard || 'N/A',
|
// value: navigator.keyboard,
|
||||||
// prototype: Navigator.prototype.hardwareConcurrency,
|
// prototype: Navigator.prototype.hardwareConcurrency,
|
||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
|
|
@ -90,22 +90,17 @@ const getNavigator = () => {
|
||||||
{
|
{
|
||||||
key: 'vendor',
|
key: 'vendor',
|
||||||
title: 'Vendor',
|
title: 'Vendor',
|
||||||
value: navigator.vendor || 'N/A',
|
value: navigator.vendor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'appVersion',
|
key: 'appVersion',
|
||||||
title: 'App version',
|
title: 'App version',
|
||||||
value: navigator.appVersion || 'N/A',
|
value: navigator.appVersion,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'productSub',
|
key: 'productSub',
|
||||||
title: 'Product sub',
|
title: 'Product sub',
|
||||||
value: navigator.productSub || 'N/A',
|
value: navigator.productSub,
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'vendorSub',
|
|
||||||
title: 'Vendor sub',
|
|
||||||
value: navigator.vendorSub || 'N/A',
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
return data;
|
return data;
|
||||||
|
|
@ -149,18 +144,23 @@ const checkUndefinedProperties = (obj) => {
|
||||||
// document.body.appendChild(frame);
|
// document.body.appendChild(frame);
|
||||||
// }
|
// }
|
||||||
// console.log(navigator.hardwareConcurrency);
|
// console.log(navigator.hardwareConcurrency);
|
||||||
let w;
|
|
||||||
if (typeof Worker !== 'undefined') {
|
|
||||||
if (typeof w === 'undefined') {
|
|
||||||
w = new Worker('/worker.js');
|
|
||||||
}
|
|
||||||
w.onmessage = (event) => {
|
|
||||||
console.log(event);
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
document.getElementById('result').innerHTML =
|
|
||||||
'Sorry! No Web Worker support.';
|
|
||||||
}
|
|
||||||
|
|
||||||
return list.toString().split(',').join('<br />');
|
return list.toString().split(',').join('<br />');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkWebWorker = (obj, setWorkerData) => {
|
||||||
|
let w;
|
||||||
|
if (typeof w === 'undefined') {
|
||||||
|
w = new Worker('/worker.js');
|
||||||
|
}
|
||||||
|
w.postMessage(obj.key);
|
||||||
|
w.onmessage = (event) => {
|
||||||
|
if (
|
||||||
|
event.data !== undefined &&
|
||||||
|
event.data.toString() !== navigator[obj.key].toString()
|
||||||
|
) {
|
||||||
|
console.log(event.data, navigator[obj.key]);
|
||||||
|
setWorkerData('Did not match web worker');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -9134,6 +9134,11 @@ react-tsparticles@^1.28.0:
|
||||||
tslib "^2.2.0"
|
tslib "^2.2.0"
|
||||||
tsparticles "^1.28.0"
|
tsparticles "^1.28.0"
|
||||||
|
|
||||||
|
react-webworker@^2.1.0:
|
||||||
|
version "2.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/react-webworker/-/react-webworker-2.1.0.tgz#6bfe5d74d3f3e5bae89f316b8760b3e8cc551420"
|
||||||
|
integrity sha512-Rl0LeJa7zAQHAZ5KpyWQ/7aHcdy6AKJcJI7UIGlFo2e2sJw7u87hg4ck1cWb70DO0PrW0NwNZrMCgTi23g09JQ==
|
||||||
|
|
||||||
react@^17.0.2:
|
react@^17.0.2:
|
||||||
version "17.0.2"
|
version "17.0.2"
|
||||||
resolved "https://registry.npmjs.org/react/-/react-17.0.2.tgz"
|
resolved "https://registry.npmjs.org/react/-/react-17.0.2.tgz"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue