Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web workers: how to know if the browser supports it?

What's the best way to know if the running browser supports web-workers ?

is it

try { new Worker(); } catch (e) { /* it does not */ }

Thanks

like image 237
Lx1 Avatar asked Sep 10 '10 12:09

Lx1


2 Answers

This is the code the script Modernizr uses:

tests[webWorkers] = function () {
    return !!window.Worker;
};
like image 112
Yi Jiang Avatar answered Nov 15 '22 03:11

Yi Jiang


You can try window.Worker in your browser's console to check if the function exists. In your javascript code you can try this:

if (typeof(Worker) !== "undefined") {
   //great, your browser supports web workers
} else {
   //not supported
}
like image 22
Roy R Avatar answered Nov 15 '22 04:11

Roy R