Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WebWorker Feature Check
self.onmessage = ({data}) => {
self.postMessage(data.reduce((o, v, i) => {
o[v] = !!self[v]
return o;
}, {}));
};
let checkWorkerFeatures = (features) => {
return new Promise((resolve, reject) => {
const threadCheck = new Worker('feature.thread.js');
threadCheck.onmessage = ({data}) => resolve(data) && threadCheck.terminate();
threadCheck.postMessage(features);
})
};
checkWorkerFeatures(['WebSocket', 'localStorage', 'indexedDB']).then(console.log.bind(console));
// Logs: `Object {WebSocket: true, localStorage: false, indexedDB: true}` in latest Chrome:stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment