Install
npm install --save detect-webworker
Usage:
var isWebWorker = ; if isWebWorker console; else console;
The check is performed as:
moduleexports = false;try moduleexports = self instanceof WorkerGlobalScope catche {}
Inspired from detect-node and idea taken from this stackoverflow issue